runtime

package
v0.30.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2026 License: MIT Imports: 32 Imported by: 0

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

View Source
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
)
View Source
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

This section is empty.

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 BlockOf

func BlockOf(v Value) *Block

BlockOf returns the *Block stored in v, or nil.

func (*Block) ValueBlockMarker

func (*Block) ValueBlockMarker()

type BlockLiteral

type BlockLiteral = ast.BlockLiteral

type BoolLiteral

type BoolLiteral = ast.BoolLiteral

type BreakStmt

type BreakStmt = ast.BreakStmt

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 BuiltinOf

func BuiltinOf(v Value) *Builtin

BuiltinOf returns the *Builtin stored in v, or nil.

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 CallExpr

type CallExpr = ast.CallExpr

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

type CapabilityBinding struct {
	Context context.Context
	Engine  *Engine
}

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 CaseExpr

type CaseExpr = ast.CaseExpr

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

func ClassOf(v Value) *ClassDef

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 ClassStmt

type ClassStmt = ast.ClassStmt

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
}

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

type Database = db.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

type Duration = value.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

func MustNewEngine(cfg Config) *Engine

MustNewEngine constructs an Engine or panics if the config is invalid.

func NewEngine

func NewEngine(cfg Config) (*Engine, error)

NewEngine constructs an Engine with sane defaults and registers built-ins.

func (*Engine) Builtins

func (e *Engine) Builtins() map[string]Value

Builtins returns a copy of the registered builtin map.

func (*Engine) ClearModuleCache

func (e *Engine) ClearModuleCache() int

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) Compile

func (e *Engine) Compile(source string) (*Script, error)

func (*Engine) ConfigSummary

func (e *Engine) ConfigSummary() string

ConfigSummary provides a human-readable description of the interpreter limits.

func (*Engine) Execute

func (e *Engine) Execute(ctx context.Context, script string) error

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 EnumOf

func EnumOf(v Value) *EnumDef

EnumOf returns the *EnumDef stored in v, or nil.

func (*EnumDef) ValueEnumMarker

func (*EnumDef) ValueEnumMarker()

type EnumMemberStmt

type EnumMemberStmt = ast.EnumMemberStmt

type EnumStmt

type EnumStmt = ast.EnumStmt

type EnumValueDef

type EnumValueDef struct {
	Enum   *EnumDef
	Name   string
	Symbol string
	Index  int
}

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.

func (*Env) Assign

func (e *Env) Assign(name string, val Value) bool

Assign updates an existing variable in the nearest enclosing scope, or defines it in the current scope.

func (*Env) CloneShallow

func (e *Env) CloneShallow() *Env

CloneShallow returns a copy of the environment with the same parent and a shallow copy of its bindings.

func (*Env) Define

func (e *Env) Define(name string, val Value)

Define binds a new variable in the current scope.

func (*Env) Get

func (e *Env) Get(name string) (Value, bool)

Get looks up a variable by name, traversing parent scopes if needed.

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

type EventPublisher = events.Publisher

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

func (exec *Execution) CallBlock(block Value, args []Value) (Value, error)

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

func (exec *Execution) Context() context.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.

func (*Execution) Step

func (exec *Execution) Step() error

Step accounts for one interpreter step against quota and memory limits and returns the deadline error when the script's context has been canceled. Capability adapters call it inside per-row loops so long-running host callbacks honor the same budget as in-script work.

type ExprStmt

type ExprStmt = ast.ExprStmt

type Expression

type Expression = ast.Expression

type FloatLiteral

type FloatLiteral = ast.FloatLiteral

type ForStmt

type ForStmt = ast.ForStmt

type FunctionStmt

type FunctionStmt = ast.FunctionStmt

type HashLiteral

type HashLiteral = ast.HashLiteral

type HashPair

type HashPair = ast.HashPair

type Identifier

type Identifier = ast.Identifier

type IfStmt

type IfStmt = ast.IfStmt

type IndexExpr

type IndexExpr = ast.IndexExpr

type Instance

type Instance struct {
	Class *ClassDef
	Ivars map[string]Value
}

Instance represents a runtime instance of a ClassDef with its own instance variables.

func InstanceOf

func InstanceOf(v Value) *Instance

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 IvarExpr

type IvarExpr = ast.IvarExpr

type JobQueue

type JobQueue = jobqueue.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

type Money = value.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 NextStmt

type NextStmt = ast.NextStmt

type NilLiteral

type NilLiteral = ast.NilLiteral

type Node

type Node = ast.Node

type Param

type Param = ast.Param

type Position

type Position = source.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 Program

type Program = ast.Program

type PropertyDecl

type PropertyDecl = ast.PropertyDecl

type RaiseStmt

type RaiseStmt = ast.RaiseStmt

type Range

type Range = value.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 RangeExpr

type RangeExpr = ast.RangeExpr

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 ScopeExpr

type ScopeExpr = ast.ScopeExpr

type Script

type Script struct {
	// contains filtered or unexported fields
}

Script represents a parsed Vibescript module ready for execution.

func (*Script) Call

func (s *Script) Call(ctx context.Context, name string, args []Value, opts CallOptions) (Value, error)

func (*Script) Classes

func (s *Script) Classes() []*ClassDef

Classes returns compiled classes in deterministic name order.

func (*Script) Enums

func (s *Script) Enums() []*EnumDef

Enums returns compiled enums in deterministic name order.

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
}

StackFrame represents a single entry in a runtime error's call stack.

type Statement

type Statement = ast.Statement

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 Token

type Token = ast.Token

type TokenType

type TokenType = ast.TokenType

type TryStmt

type TryStmt = ast.TryStmt

type TypeExpr

type TypeExpr = ast.TypeExpr

type TypeKind

type TypeKind = ast.TypeKind

type UnaryExpr

type UnaryExpr = ast.UnaryExpr

type UntilStmt

type UntilStmt = ast.UntilStmt

type Value

type Value = value.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 NewArray

func NewArray(a []Value) Value

NewArray returns an array Value.

func NewAutoBuiltin

func NewAutoBuiltin(name string, fn BuiltinFunc) Value

NewAutoBuiltin returns a builtin function Value that auto-invokes without parentheses.

func NewBlock

func NewBlock(params []Param, body []Statement, env *Env) Value

NewBlock returns a block (closure) Value.

func NewBool

func NewBool(b bool) Value

NewBool returns a boolean Value.

func NewBuiltin

func NewBuiltin(name string, fn BuiltinFunc) Value

NewBuiltin returns a builtin function Value.

func NewClass

func NewClass(def *ClassDef) Value

NewClass returns a class definition Value.

func NewDuration

func NewDuration(d Duration) Value

NewDuration returns a duration Value.

func NewEnum

func NewEnum(def *EnumDef) Value

NewEnum returns an enum definition Value.

func NewEnumValue

func NewEnumValue(def *EnumValueDef) Value

NewEnumValue returns an enum member Value.

func NewFloat

func NewFloat(f float64) Value

NewFloat returns a floating-point Value.

func NewFunction

func NewFunction(fn *ScriptFunction) Value

NewFunction returns a script-defined function Value.

func NewHash

func NewHash(h map[string]Value) Value

NewHash returns a hash (map) Value.

func NewInstance

func NewInstance(inst *Instance) Value

NewInstance returns a class instance Value.

func NewInt

func NewInt(i int64) Value

NewInt returns an integer Value.

func NewMoney

func NewMoney(m Money) Value

NewMoney returns a money Value.

func NewNil

func NewNil() Value

NewNil returns a nil Value.

func NewObject

func NewObject(attrs map[string]Value) Value

NewObject returns an object Value with the given attributes.

func NewRange

func NewRange(r Range) Value

NewRange returns a range Value.

func NewString

func NewString(s string) Value

NewString returns a string Value.

func NewSymbol

func NewSymbol(name string) Value

NewSymbol returns a symbol Value.

func NewTime

func NewTime(t time.Time) Value

NewTime returns a time Value.

type ValueKind

type ValueKind = value.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.

type WhileStmt

type WhileStmt = ast.WhileStmt

type YieldExpr

type YieldExpr = ast.YieldExpr

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL