Documentation
¶
Index ¶
- Constants
- func ClearVMPool()
- type Addr
- type Condition
- type Context
- type Converter
- type Function
- type Instruction
- type InstructionInfo
- type NativeFunction
- type Operation
- type PanicError
- func (p *PanicError) Error() string
- func (p *PanicError) Message() interface{}
- func (p *PanicError) Next() *PanicError
- func (p *PanicError) Path() string
- func (p *PanicError) Position() Position
- func (p *PanicError) Recovered() bool
- func (p *PanicError) StackFrames() []StackFrame
- func (p *PanicError) StackTrace() []byte
- func (p *PanicError) String() string
- type Position
- type PrintFunc
- type ProfileCallKind
- type ProfileCallRecord
- type ProfileData
- type Registers
- type ScriggoType
- type SpecializationMetadata
- type StackFrame
- type StackShift
- type TypeOfFunc
- type VM
- func (vm *VM) GetProfileData() *ProfileData
- func (vm *VM) Reset()
- func (vm *VM) Run(fn *Function, typeof TypeOfFunc, globals []reflect.Value) error
- func (vm *VM) SetContext(ctx context.Context)
- func (vm *VM) SetMaxParallelRenders(n int)
- func (vm *VM) SetPrint(p PrintFunc)
- func (vm *VM) SetProfiling(enabled bool)
- func (vm *VM) SetRenderer(out io.Writer, conv Converter)
- func (vm *VM) Stack(buf []byte, all bool) int
Constants ¶
const CurrentFunction = -1
const NoVariadicArgs = -1
const ReturnString = -1
Variables ¶
This section is empty.
Functions ¶
func ClearVMPool ¶
func ClearVMPool()
ClearVMPool resets the VM pool, allowing accumulated VMs to be garbage collected. Call this after rendering completes to release memory from high-concurrency spikes. Thread-safe: can be called from any goroutine.
When the pool is reset, ongoing Get() operations may use the old pool briefly, which is safe - they'll just create new VMs. New operations will use the new pool. The pool will rebuild naturally on subsequent render operations.
Types ¶
type Condition ¶
type Condition int8
const ( ConditionZero Condition = iota // x == 0 ConditionNotZero // x != 0 ConditionEqual // x == y ConditionNotEqual // x != y ConditionInterfaceEqual // x == y ConditionInterfaceNotEqual // x != y ConditionLess // x < y ConditionLessEqual // x <= y ConditionGreater // x > y ConditionGreaterEqual // x >= y ConditionLessU // x < y (unsigned) ConditionLessEqualU // x <= y (unsigned) ConditionGreaterU // x > y (unsigned) ConditionGreaterEqualU // x >= y (unsigned) ConditionLenEqual // len(x) == y ConditionLenNotEqual // len(x) != y ConditionLenLess // len(x) < y ConditionLenLessEqual // len(x) <= y ConditionLenGreater // len(x) > y ConditionLenGreaterEqual // len(x) >= y ConditionInterfaceNil // x == nil ConditionInterfaceNotNil // x != nil ConditionNil // x == nil ConditionNotNil // x != nil ConditionContainsSubstring // x contains y ConditionContainsRune // x contains y ConditionContainsElement // x contains y ConditionContainsKey // x contains y ConditionContainsNil // x contains nil ConditionNotContainsSubstring // x not contains y ConditionNotContainsRune // x not contains y ConditionNotContainsElement // x not contains y ConditionNotContainsKey // x not contains y ConditionNotContainsNil // x not contains nil ConditionOK // [vm.ok] ConditionNotOK // ![vm.ok] )
type Function ¶
type Function struct {
Pkg string
Name string
File string
Pos *Position // position of the function declaration.
Type reflect.Type
Parent *Function
// VarRefs refers to the non-local variables referenced in this function.
//
// If VarRefs is nil, it means that the non-local variables are the global
// variables passed through the env.
//
// Otherwise, for each var Ref in VarRefs:
//
// * if Ref >= 0, Ref refers to the non-local variable at index Ref of the
// currently executing function
//
// * if Ref < 0, it refers to the general register -Ref of the currently
// executing function, which will contain the value of that variable
// (indirectly).
VarRefs []int16
Types []reflect.Type
NumReg [4]int8
FinalRegs [][2]int8 // [indirect -> return parameter registers]
Macro bool
Format ast.Format
Values Registers
FieldIndexes [][]int
Functions []*Function
NativeFunctions []*NativeFunction
Body []Instruction
Text [][]byte
InstructionInfo map[Addr]InstructionInfo
// contains filtered or unexported fields
}
Function represents a function.
func (*Function) GetSpecialization ¶
func (fn *Function) GetSpecialization(addr Addr) *SpecializationMetadata
GetSpecialization returns the specialization metadata for instruction at addr. Returns nil if specializations haven't been allocated yet.
func (*Function) TrySpecialize ¶
func (fn *Function) TrySpecialize(addr Addr, specialize func(*SpecializationMetadata) Operation) Operation
TrySpecialize attempts to specialize an instruction at addr. Returns the specialized opcode if successful, or 0 if already specialized/failed. Uses atomic CAS to ensure only one goroutine performs specialization.
type Instruction ¶
type InstructionInfo ¶
type InstructionInfo struct {
Position Position // position of the instruction in the source code.
Path string // path of the source code where the instruction is located in.
OperandKind [3]reflect.Kind // kind of operands A, B and C.
FuncType reflect.Type // type of the function that is called; only for call instructions.
}
InstructionInfo represents a set of information associated to a given instruction. None of the fields below is mandatory.
type NativeFunction ¶
type NativeFunction struct {
// contains filtered or unexported fields
}
func NewNativeFunction ¶
func NewNativeFunction(pkg, name string, function interface{}) *NativeFunction
NewNativeFunction returns a new native function given its package and name and the function value or its reflect value. pkg and name can be empty strings.
func (*NativeFunction) Func ¶
func (fn *NativeFunction) Func() interface{}
func (*NativeFunction) Name ¶
func (fn *NativeFunction) Name() string
func (*NativeFunction) Package ¶
func (fn *NativeFunction) Package() string
type Operation ¶
type Operation int8
const ( OpNone Operation = iota OpAdd OpAddInt OpAddFloat64 OpAddr OpAnd OpAndNot OpAssert OpAppend OpAppendSlice OpBreak OpCallFunc OpCallIndirect OpCallMacro OpCallNative OpCap OpCase OpClose OpComplex64 OpComplex128 OpConcat OpContinue OpConvert OpConvertInt OpConvertUint OpConvertFloat OpConvertString OpConvertFromInterface OpCopy OpDefer OpDelete OpDiv OpDivInt OpDivFloat64 OpField OpGetVar OpGetVarAddr OpGo OpGoRender OpGoRenderIndirect OpGoRenderWait OpGoto OpIf OpIfInt OpIfFloat OpIfString OpIndex OpIndexString OpIndexRef OpLen OpLoad OpLoadFunc OpMakeArray OpMakeChan OpMakeMap OpMakeSlice OpMakeStruct OpMapIndex OpMapIndexAny OpMethodValue OpMove OpMul OpMulInt OpMulFloat64 OpNeg OpNew OpOr OpPanic OpPrint OpRange OpRangeInterface OpRangeString OpRealImag OpReceive OpRecover OpRem OpRemInt OpReturn OpSelect OpSend OpSetField OpSetMap OpSetSlice OpSetVar OpShl OpShlInt OpShow OpShr OpShrInt OpSlice OpStringSlice OpSub OpSubInt OpSubFloat64 OpSubInv OpSubInvInt OpSubInvFloat64 OpTailCall OpText OpTypify OpXor OpZero // Super-instructions: fused opcodes for common patterns OpFieldShow // Fused: OpField + OpShow (field access followed by display) OpMapIndexShow // Fused: OpMapIndex + OpShow (map access followed by display) // Specialized opcodes for common type patterns (Phase 3 - Bytecode Specialization) OpMapIndexStringString // Specialized: map[string]string index OpMapIndexStringInt // Specialized: map[string]int index OpMapIndexStringBool // Specialized: map[string]bool index OpFieldDirect // Specialized: direct single-level struct field access )
type PanicError ¶
type PanicError struct {
// contains filtered or unexported fields
}
func (*PanicError) Error ¶
func (p *PanicError) Error() string
Error returns all currently active panics as a string.
To print only the message, use the String method instead.
func (*PanicError) Message ¶
func (p *PanicError) Message() interface{}
Message returns the message.
func (*PanicError) Next ¶
func (p *PanicError) Next() *PanicError
Next returns the next panic in the chain.
func (*PanicError) Path ¶
func (p *PanicError) Path() string
Path returns the path of the file that panicked.
func (*PanicError) Position ¶
func (p *PanicError) Position() Position
Position returns the position.
func (*PanicError) Recovered ¶
func (p *PanicError) Recovered() bool
Recovered reports whether it has been recovered.
func (*PanicError) StackFrames ¶
func (p *PanicError) StackFrames() []StackFrame
StackFrames returns the call stack as structured frames.
func (*PanicError) StackTrace ¶
func (p *PanicError) StackTrace() []byte
StackTrace returns the stack trace at the point of the panic.
func (*PanicError) String ¶
func (p *PanicError) String() string
String returns the message as a string.
type Position ¶
type Position struct {
Line int // line starting from 1
Column int // column in characters starting from 1
Start int // index of the first byte
End int // index of the last byte
}
Position represents a source position.
type ProfileCallKind ¶
type ProfileCallKind int
ProfileCallKind distinguishes different types of calls in profiling. These values map to scriggo.CallKind in the public API (see profile.go).
const ( ProfileCallKindScriggoFunc ProfileCallKind = iota ProfileCallKindNativeFunc ProfileCallKindMacro )
type ProfileCallRecord ¶
type ProfileCallRecord struct {
ID uint64
ParentID uint64
Name string
Package string
File string
Line int
Kind ProfileCallKind
StartTime time.Time
Duration time.Duration
SelfDuration time.Duration
TemplatePath string
}
ProfileCallRecord represents a single function or macro invocation during profiling. This type maps to scriggo.CallRecord in the public API (see profile.go).
type ProfileData ¶
type ProfileData struct {
StartTime time.Time
EndTime time.Time
TotalDuration time.Duration
Calls []*ProfileCallRecord
}
ProfileData contains the raw profiling data collected during execution. This type maps to scriggo.Profile in the public API (see profile.go).
type ScriggoType ¶
type ScriggoType interface {
reflect.Type
// Wrap wraps a value with a Scriggo type putting into a proxy that exposes
// methods to Go.
Wrap(reflect.Value) reflect.Value
// Unwrap unwraps a value that has been read from Go. If the value given as
// parameter can be unwrapped using the unwrapper's type, the unwrapped
// value is returned and the method returns true.
Unwrap(reflect.Value) (reflect.Value, bool)
// GoType returns the Go type of a Scriggo type. Note that the
// implementation of the reflect.Type returned by GoType is the
// implementation of the package 'reflect', so it's safe to pass the
// returned value to reflect functions and methods as argument.
GoType() reflect.Type
}
A ScriggoType represents a type compiled by Scriggo from a type definition or a composite type literal with at least one element with a Scriggo type.
type SpecializationMetadata ¶
type SpecializationMetadata struct {
// contains filtered or unexported fields
}
SpecializationMetadata holds runtime type information for instruction specialization. This is a sidecar structure that doesn't modify the original instruction, ensuring concurrent safety for multiple VMs executing the same bytecode.
type StackFrame ¶
type StackFrame struct {
Function string // Function name (e.g., "content")
Path string // File path (e.g., "partial.html")
Line int // Line number
}
StackFrame represents a single frame in the call stack.
type StackShift ¶
type StackShift [4]int8
type TypeOfFunc ¶
A TypeOfFunc function returns a type of a value.
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM represents a Scriggo virtual machine.
func (*VM) GetProfileData ¶
func (vm *VM) GetProfileData() *ProfileData
GetProfileData returns the collected profiling data, or nil if profiling was not enabled.
func (*VM) Reset ¶
func (vm *VM) Reset()
Reset resets a virtual machine so that it is ready for a new call to Run.
func (*VM) Run ¶
Run starts the execution of the function fn with the given global variables and waits for it to complete.
During the execution if a panic occurs and has not been recovered, by default Run panics with the panic message.
If a context has been set and the context is canceled, Run returns as soon as possible with the error returned by the Err method of the context.
func (*VM) SetContext ¶
SetContext sets the context.
SetContext must not be called after vm has been started.
func (*VM) SetMaxParallelRenders ¶
SetMaxParallelRenders sets the maximum number of concurrent "go render" operations. If n is zero or negative, the default (2*GOMAXPROCS) is used.
SetMaxParallelRenders must be called after SetRenderer and before vm has been started.
func (*VM) SetPrint ¶
SetPrint sets the "print" builtin function.
SetPrint must not be called after vm has been started.
func (*VM) SetProfiling ¶
SetProfiling enables or disables profiling. When enabled, the VM will collect timing data for function calls, macros, and includes.
SetProfiling must not be called after vm has been started.
func (*VM) SetRenderer ¶
SetRenderer sets template output and markdown converter.
SetRenderer must not be called after vm has been started.