Documentation
¶
Overview ¶
Package runtime implements the Vibescript execution engine — the Engine, Script, Execution, environment, memory accounting, module loader, and built-in registration. It is hidden from external embedders behind the vibes facade.
Index ¶
- Constants
- func MemberCompletionNames() map[string][]string
- type ArrayLiteral
- type AssignStmt
- type BinaryExpr
- type Block
- type BlockLiteral
- type BoolLiteral
- type BreakStmt
- type Builtin
- type BuiltinFunc
- type CallExpr
- type CallOptions
- type CapabilityAdapter
- func MustNewContextCapability(name string, resolver ContextCapabilityResolver) CapabilityAdapter
- func MustNewDBCapability(name string, impl Database) CapabilityAdapter
- func MustNewEventsCapability(name string, publisher EventPublisher) CapabilityAdapter
- func MustNewJobQueueCapability(name string, impl JobQueue) CapabilityAdapter
- func NewContextCapability(name string, resolver ContextCapabilityResolver) (CapabilityAdapter, error)
- func NewDBCapability(name string, impl Database) (CapabilityAdapter, error)
- func NewEventsCapability(name string, publisher EventPublisher) (CapabilityAdapter, error)
- func NewJobQueueCapability(name string, impl JobQueue) (CapabilityAdapter, error)
- type CapabilityBinding
- type CapabilityContractProvider
- type CapabilityMethodContract
- type CaseExpr
- type CaseWhenClause
- type ClassDef
- type ClassStmt
- type ClassVarExpr
- type Config
- type ContextCapabilityResolver
- type DBEachRequest
- type DBFindRequest
- type DBQueryRequest
- type DBSumRequest
- type DBUpdateRequest
- type Database
- type DatabaseReader
- type DatabaseWriter
- type Duration
- type Engine
- func (e *Engine) Builtins() map[string]Value
- func (e *Engine) ClearModuleCache() int
- func (e *Engine) Compile(source string) (*Script, error)
- func (e *Engine) ConfigSummary() string
- func (e *Engine) Execute(ctx context.Context, script string) error
- func (e *Engine) RegisterBuiltin(name string, fn BuiltinFunc)
- func (e *Engine) RegisterZeroArgBuiltin(name string, fn BuiltinFunc)
- type EnumDef
- type EnumMemberStmt
- type EnumStmt
- type EnumValueDef
- type Env
- type EventPublishRequest
- type EventPublisher
- type Execution
- type ExprStmt
- type Expression
- type FloatLiteral
- type ForStmt
- type FunctionStmt
- type HashLiteral
- type HashPair
- type Identifier
- type IfStmt
- type IndexExpr
- type Instance
- type IntegerLiteral
- type InterpolatedString
- type IvarExpr
- type JobQueue
- type JobQueueEnqueueOptions
- type JobQueueJob
- type JobQueueRetryRequest
- type JobQueueWithRetry
- type KeywordArg
- type MemberExpr
- type Money
- type NextStmt
- type NilLiteral
- type Node
- type Param
- type ParseIssue
- type Position
- type Program
- type PropertyDecl
- type RaiseStmt
- type Range
- type RangeExpr
- type ReturnStmt
- type RuntimeError
- type ScopeExpr
- type Script
- type ScriptFunction
- type StackFrame
- type Statement
- type StringExpr
- type StringLiteral
- type StringPart
- type StringText
- type SymbolLiteral
- type Token
- type TokenType
- type TryStmt
- type TypeExpr
- type TypeKind
- type UnaryExpr
- type UntilStmt
- type Value
- func NewArray(a []Value) Value
- func NewAutoBuiltin(name string, fn BuiltinFunc) Value
- func NewBlock(params []Param, body []Statement, env *Env) Value
- func NewBool(b bool) Value
- func NewBuiltin(name string, fn BuiltinFunc) Value
- func NewClass(def *ClassDef) Value
- func NewDuration(d Duration) Value
- func NewEnum(def *EnumDef) Value
- func NewEnumValue(def *EnumValueDef) Value
- func NewFloat(f float64) Value
- func NewFunction(fn *ScriptFunction) Value
- func NewHash(h map[string]Value) Value
- func NewInstance(inst *Instance) Value
- func NewInt(i int64) Value
- func NewMoney(m Money) Value
- func NewNil() Value
- func NewObject(attrs map[string]Value) Value
- func NewRange(r Range) Value
- func NewString(s string) Value
- func NewSymbol(name string) Value
- func NewTime(t time.Time) Value
- type ValueKind
- type WhileStmt
- type YieldExpr
Constants ¶
const ( TypeAny = ast.TypeAny TypeInt = ast.TypeInt TypeFloat = ast.TypeFloat TypeNumber = ast.TypeNumber TypeString = ast.TypeString TypeBool = ast.TypeBool TypeNil = ast.TypeNil TypeDuration = ast.TypeDuration TypeTime = ast.TypeTime TypeMoney = ast.TypeMoney TypeArray = ast.TypeArray TypeHash = ast.TypeHash TypeFunction = ast.TypeFunction TypeShape = ast.TypeShape TypeUnion = ast.TypeUnion TypeEnum = ast.TypeEnum TypeUnknown = ast.TypeUnknown )
const ( KindNil = value.KindNil KindBool = value.KindBool KindInt = value.KindInt KindFloat = value.KindFloat KindString = value.KindString KindArray = value.KindArray KindHash = value.KindHash KindFunction = value.KindFunction KindBuiltin = value.KindBuiltin KindMoney = value.KindMoney KindDuration = value.KindDuration KindTime = value.KindTime KindSymbol = value.KindSymbol KindObject = value.KindObject KindRange = value.KindRange KindBlock = value.KindBlock KindEnum = value.KindEnum KindEnumValue = value.KindEnumValue KindClass = value.KindClass KindInstance = value.KindInstance )
Variables ¶
This section is empty.
Functions ¶
func MemberCompletionNames ¶ added in v0.50.0
MemberCompletionNames returns the builtin member-method names per receiver type, for editor tooling such as LSP completion. The slices are copies; callers may sort or mutate them freely.
Types ¶
type ArrayLiteral ¶
type ArrayLiteral = ast.ArrayLiteral
type AssignStmt ¶
type AssignStmt = ast.AssignStmt
type BinaryExpr ¶
type BinaryExpr = ast.BinaryExpr
type Block ¶
type Block struct {
Params []Param
Body []Statement
Env *Env
// contains filtered or unexported fields
}
Block represents a closure passed to a function at runtime. It stays in the vibes package because its fields reference parser AST and the runtime Env/Script types.
func (*Block) ValueBlockMarker ¶
func (*Block) ValueBlockMarker()
type BlockLiteral ¶
type BlockLiteral = ast.BlockLiteral
type BoolLiteral ¶
type BoolLiteral = ast.BoolLiteral
type Builtin ¶
type Builtin struct {
Name string
Fn BuiltinFunc
AutoInvoke bool
}
Builtin represents a built-in function callable from Vibescript. It remains defined in the vibes package because BuiltinFunc references the runtime *Execution type.
func (*Builtin) ValueBuiltinMarker ¶
func (*Builtin) ValueBuiltinMarker()
type BuiltinFunc ¶
type BuiltinFunc func(exec *Execution, receiver Value, args []Value, kwargs map[string]Value, block Value) (Value, error)
BuiltinFunc is the Go function signature for built-in Vibescript functions.
type CallOptions ¶
type CallOptions struct {
Globals map[string]Value
Capabilities []CapabilityAdapter
AllowRequire bool
Keywords map[string]Value
}
CallOptions configures globals, capabilities, and other settings for a script invocation.
type CapabilityAdapter ¶
type CapabilityAdapter interface {
Bind(binding CapabilityBinding) (map[string]Value, error)
}
CapabilityAdapter binds host capabilities into a script invocation.
func MustNewContextCapability ¶
func MustNewContextCapability(name string, resolver ContextCapabilityResolver) CapabilityAdapter
MustNewContextCapability is the panicking variant of NewContextCapability.
func MustNewDBCapability ¶
func MustNewDBCapability(name string, impl Database) CapabilityAdapter
MustNewDBCapability is the panicking variant of NewDBCapability.
func MustNewEventsCapability ¶
func MustNewEventsCapability(name string, publisher EventPublisher) CapabilityAdapter
MustNewEventsCapability is the panicking variant of NewEventsCapability.
func MustNewJobQueueCapability ¶
func MustNewJobQueueCapability(name string, impl JobQueue) CapabilityAdapter
MustNewJobQueueCapability is the panicking variant of NewJobQueueCapability.
func NewContextCapability ¶
func NewContextCapability(name string, resolver ContextCapabilityResolver) (CapabilityAdapter, error)
NewContextCapability constructs a data-only context capability adapter that bridges a contextcap.Resolver into the runtime CapabilityAdapter interface. The vibes facade re-exports this entry point under the same name.
func NewDBCapability ¶
func NewDBCapability(name string, impl Database) (CapabilityAdapter, error)
NewDBCapability constructs a database capability adapter bound to the provided script-facing name. The vibes facade re-exports this entry point under the same name.
func NewEventsCapability ¶
func NewEventsCapability(name string, publisher EventPublisher) (CapabilityAdapter, error)
NewEventsCapability constructs a CapabilityAdapter that delegates to a *events.Capability. The vibes facade re-exports this entry point under the same name.
func NewJobQueueCapability ¶
func NewJobQueueCapability(name string, impl JobQueue) (CapabilityAdapter, error)
NewJobQueueCapability constructs a CapabilityAdapter that delegates to a *jobqueue.Capability. It is the runtime-facing entry point used by the vibes facade.
type CapabilityBinding ¶
CapabilityBinding provides execution context for adapters during binding.
type CapabilityContractProvider ¶
type CapabilityContractProvider interface {
CapabilityContracts() map[string]CapabilityMethodContract
}
CapabilityContractProvider exposes per-method contracts for capability adapters. Contract keys must match builtin method names exposed to scripts (for example "jobs.enqueue").
type CapabilityMethodContract ¶
type CapabilityMethodContract struct {
ValidateArgs func(args []Value, kwargs map[string]Value, block Value) error
ValidateReturn func(result Value) error
}
CapabilityMethodContract validates capability method calls at the boundary. These contracts run before and after a capability builtin executes.
type CaseWhenClause ¶
type CaseWhenClause = ast.CaseWhenClause
type ClassDef ¶
type ClassDef struct {
Name string
Methods map[string]*ScriptFunction
ClassMethods map[string]*ScriptFunction
ClassVars map[string]Value
Body []Statement
// contains filtered or unexported fields
}
ClassDef represents a user-defined class with its methods and class-level state.
func ClassOf ¶
ClassOf returns the *ClassDef stored in v, or nil if v is not a class value. It is the typed companion to v.Class(), which returns the value.ClassPayload interface for cycle-free reach from outside vibes.
func (*ClassDef) ValueClassMarker ¶
func (*ClassDef) ValueClassMarker()
type ClassVarExpr ¶
type ClassVarExpr = ast.ClassVarExpr
type Config ¶
type Config struct {
StepQuota int
MemoryQuotaBytes int
StrictEffects bool
RecursionLimit int
ModulePaths []string
ModuleAllowList []string
ModuleDenyList []string
RandomReader io.Reader
MaxCachedModules int
MaxSourceBytes int
DefaultTaskConcurrency int
MaxTaskConcurrency int
}
Config controls interpreter execution bounds and enforcement modes.
type ContextCapabilityResolver ¶
type ContextCapabilityResolver = contextcap.Resolver
ContextCapabilityResolver is an internal alias for contextcap.Resolver so runtime code (and tests) can keep using the short name that matches the public vibes facade.
type DBEachRequest ¶
type DBEachRequest = db.DBEachRequest
Internal aliases for db capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type DBFindRequest ¶
type DBFindRequest = db.DBFindRequest
Internal aliases for db capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type DBQueryRequest ¶
type DBQueryRequest = db.DBQueryRequest
Internal aliases for db capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type DBSumRequest ¶
type DBSumRequest = db.DBSumRequest
Internal aliases for db capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type DBUpdateRequest ¶
type DBUpdateRequest = db.DBUpdateRequest
Internal aliases for db capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type Database ¶
Internal aliases for db capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type DatabaseReader ¶
type DatabaseReader = db.DatabaseReader
Internal aliases for db capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type DatabaseWriter ¶
type DatabaseWriter = db.DatabaseWriter
Internal aliases for db capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type Duration ¶
Internal aliases for the value package types so runtime code can keep referring to short names (Value, Money, KindInt, NewNil, etc.) without repeating the value. prefix everywhere. These mirror the public re-exports in vibes/value_alias.go and exist purely to keep the runtime sources readable after the move out of package vibes.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine executes Vibescript programs with deterministic limits.
func MustNewEngine ¶
MustNewEngine constructs an Engine or panics if the config is invalid.
func (*Engine) ClearModuleCache ¶
ClearModuleCache drops all cached modules and returns the number of entries removed. Long-running hosts can call this between script runs to force fresh module reloads.
func (*Engine) ConfigSummary ¶
ConfigSummary provides a human-readable description of the interpreter limits.
func (*Engine) Execute ¶
Execute compiles the provided source ensuring it is valid under current config.
func (*Engine) RegisterBuiltin ¶
func (e *Engine) RegisterBuiltin(name string, fn BuiltinFunc)
RegisterBuiltin registers a callable global available to scripts.
func (*Engine) RegisterZeroArgBuiltin ¶
func (e *Engine) RegisterZeroArgBuiltin(name string, fn BuiltinFunc)
RegisterZeroArgBuiltin registers a builtin that can be invoked without arguments or parentheses.
type EnumDef ¶
type EnumDef struct {
Name string
Members map[string]*EnumValueDef
MembersByKey map[string]*EnumValueDef
Order []string
// contains filtered or unexported fields
}
EnumDef represents a user-defined enumeration with named members.
func (*EnumDef) ValueEnumMarker ¶
func (*EnumDef) ValueEnumMarker()
type EnumMemberStmt ¶
type EnumMemberStmt = ast.EnumMemberStmt
type EnumValueDef ¶
EnumValueDef represents a single member within an EnumDef.
func EnumValueOf ¶
func EnumValueOf(v Value) *EnumValueDef
EnumValueOf returns the *EnumValueDef stored in v, or nil.
func (*EnumValueDef) ValueEnumValueMarker ¶
func (*EnumValueDef) ValueEnumValueMarker()
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env represents a lexical scope that maps variable names to values.
Bindings live in two maps: values holds normal script bindings, while statics holds bindings whose deep size never changes after definition (builtins, per-call function clones). Statics are stored separately so memory-quota estimation can account for them in O(1) through the staticBytes counter instead of re-walking every binding on each check — the root env's builtin set dominated estimation cost otherwise.
func (*Env) Assign ¶
Assign updates an existing variable in the nearest enclosing scope. Names not bound anywhere are defined in the outermost mutable scope, and names found in a frozen scope rebind in the nearest mutable scope below it, so engine-shared bindings are never written.
func (*Env) CloneShallow ¶
CloneShallow returns a copy of the environment with the same parent and a shallow copy of its bindings.
func (*Env) DefineStatic ¶ added in v0.40.0
DefineStatic binds a variable whose deep size is fixed at definition time, keeping it out of the per-check estimation walk.
type EventPublishRequest ¶
type EventPublishRequest = events.PublishRequest
Internal aliases for events capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type EventPublisher ¶
Internal aliases for events capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type Execution ¶
type Execution struct {
// contains filtered or unexported fields
}
Execution holds the runtime state for a single script evaluation.
func (*Execution) CallBlock ¶
CallBlock invokes a block value with the provided arguments. This is the public entry point for capability adapters that need to call user-supplied blocks (e.g. db.each, db.tx).
func (*Execution) Context ¶
Context returns the execution's bound context. Capability adapters that have been carved into sibling packages (vibes/capability/...) rely on it to forward cancellation and request-scoped values to host callbacks without reaching into unexported runtime fields.
type Expression ¶
type Expression = ast.Expression
type FloatLiteral ¶
type FloatLiteral = ast.FloatLiteral
type FunctionStmt ¶
type FunctionStmt = ast.FunctionStmt
type HashLiteral ¶
type HashLiteral = ast.HashLiteral
type Identifier ¶
type Identifier = ast.Identifier
type Instance ¶
Instance represents a runtime instance of a ClassDef with its own instance variables.
func InstanceOf ¶
InstanceOf returns the *Instance stored in v, or nil.
func (*Instance) ValueInstanceMarker ¶
func (*Instance) ValueInstanceMarker()
type IntegerLiteral ¶
type IntegerLiteral = ast.IntegerLiteral
type InterpolatedString ¶
type InterpolatedString = ast.InterpolatedString
type JobQueue ¶
Internal aliases for jobqueue capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type JobQueueEnqueueOptions ¶
type JobQueueEnqueueOptions = jobqueue.JobQueueEnqueueOptions
Internal aliases for jobqueue capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type JobQueueJob ¶
type JobQueueJob = jobqueue.JobQueueJob
Internal aliases for jobqueue capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type JobQueueRetryRequest ¶
type JobQueueRetryRequest = jobqueue.JobQueueRetryRequest
Internal aliases for jobqueue capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type JobQueueWithRetry ¶
type JobQueueWithRetry = jobqueue.JobQueueWithRetry
Internal aliases for jobqueue capability types so runtime code (and tests) can keep referring to short names that match the public vibes facade.
type KeywordArg ¶
type KeywordArg = ast.KeywordArg
type MemberExpr ¶
type MemberExpr = ast.MemberExpr
type Money ¶
Internal aliases for the value package types so runtime code can keep referring to short names (Value, Money, KindInt, NewNil, etc.) without repeating the value. prefix everywhere. These mirror the public re-exports in vibes/value_alias.go and exist purely to keep the runtime sources readable after the move out of package vibes.
type NilLiteral ¶
type NilLiteral = ast.NilLiteral
type ParseIssue ¶ added in v0.50.0
ParseIssue is one structured parse failure extracted from a Compile error. Pos is the 1-indexed position where the issue starts; End is the exclusive end of the offending token, or the zero Position when the parser could not determine a span. Message carries the bare error text without the position prefix or rendered code frame.
func ParseIssues ¶ added in v0.50.0
func ParseIssues(err error) []ParseIssue
ParseIssues extracts the structured parse failures carried by a Compile error, in source order. It returns nil for nil errors and for errors that carry no parse positions (such as size-limit or duplicate top-level name failures).
type Position ¶
Position is an internal alias for source.Position so runtime code can use the short name. AST and other internal aliases below mirror the vibes facade re-exports.
type PropertyDecl ¶
type PropertyDecl = ast.PropertyDecl
type Range ¶
Internal aliases for the value package types so runtime code can keep referring to short names (Value, Money, KindInt, NewNil, etc.) without repeating the value. prefix everywhere. These mirror the public re-exports in vibes/value_alias.go and exist purely to keep the runtime sources readable after the move out of package vibes.
type ReturnStmt ¶
type ReturnStmt = ast.ReturnStmt
type RuntimeError ¶
type RuntimeError struct {
Type string
Message string
CodeFrame string
Frames []StackFrame
}
RuntimeError represents a Vibescript runtime error with a call stack and source context.
func (*RuntimeError) Error ¶
func (re *RuntimeError) Error() string
Error returns the error message with a code frame and formatted stack trace.
func (*RuntimeError) Unwrap ¶
func (re *RuntimeError) Unwrap() error
Unwrap returns nil to satisfy the error unwrapping interface. RuntimeError is a terminal error that wraps the original error message but not the error itself.
type Script ¶
type Script struct {
// contains filtered or unexported fields
}
Script represents a parsed Vibescript module ready for execution.
func (*Script) Function ¶
func (s *Script) Function(name string) (*ScriptFunction, bool)
Function looks up a compiled function by name.
func (*Script) Functions ¶
func (s *Script) Functions() []*ScriptFunction
Functions returns compiled functions in deterministic name order.
type ScriptFunction ¶
type ScriptFunction struct {
Name string
Params []Param
ReturnTy *TypeExpr
Body []Statement
Pos Position
Env *Env
Exported bool
Private bool
// contains filtered or unexported fields
}
ScriptFunction represents a user-defined function within a Vibescript module.
func FunctionOf ¶
func FunctionOf(v Value) *ScriptFunction
FunctionOf returns the *ScriptFunction stored in v, or nil.
func (*ScriptFunction) ValueFunctionMarker ¶
func (*ScriptFunction) ValueFunctionMarker()
type StackFrame ¶
type StackFrame struct {
Function string
Pos Position
// Source is the module path for module-backed frames. It is empty for
// root scripts compiled directly by an embedder.
Source string
}
StackFrame represents a single entry in a runtime error's call stack.
type StringExpr ¶
type StringExpr = ast.StringExpr
type StringLiteral ¶
type StringLiteral = ast.StringLiteral
type StringPart ¶
type StringPart = ast.StringPart
type StringText ¶
type StringText = ast.StringText
type SymbolLiteral ¶
type SymbolLiteral = ast.SymbolLiteral
type Value ¶
Internal aliases for the value package types so runtime code can keep referring to short names (Value, Money, KindInt, NewNil, etc.) without repeating the value. prefix everywhere. These mirror the public re-exports in vibes/value_alias.go and exist purely to keep the runtime sources readable after the move out of package vibes.
func NewAutoBuiltin ¶
func NewAutoBuiltin(name string, fn BuiltinFunc) Value
NewAutoBuiltin returns a builtin function Value that auto-invokes without parentheses.
func NewBuiltin ¶
func NewBuiltin(name string, fn BuiltinFunc) Value
NewBuiltin returns a builtin function Value.
func NewEnumValue ¶
func NewEnumValue(def *EnumValueDef) Value
NewEnumValue returns an enum member Value.
func NewFunction ¶
func NewFunction(fn *ScriptFunction) Value
NewFunction returns a script-defined function Value.
func NewInstance ¶
NewInstance returns a class instance Value.
type ValueKind ¶
Internal aliases for the value package types so runtime code can keep referring to short names (Value, Money, KindInt, NewNil, etc.) without repeating the value. prefix everywhere. These mirror the public re-exports in vibes/value_alias.go and exist purely to keep the runtime sources readable after the move out of package vibes.
Source Files
¶
- aliases.go
- builtins.go
- call.go
- capabilities.go
- capability_adapters.go
- compile.go
- doc.go
- engine.go
- env.go
- errors.go
- eval.go
- execution.go
- limits.go
- member_cache.go
- members.go
- members_array.go
- members_hash.go
- members_numeric.go
- members_string.go
- members_temporal.go
- memory.go
- modules.go
- parse_issues.go
- regex_cache.go
- script.go
- suggest.go
- tasks.go
- types.go
- types_normalize.go
- types_user.go
- value_sets.go
- values.go