Documentation
¶
Overview ¶
Package eval implements the tree-walking evaluator for the interpreter.
Index ¶
- Variables
- func ApplyFunction(fn object.Object, args []object.Object, callerEnv *object.Environment, ...) object.Object
- func BuiltinByName(name string) (*object.Builtin, bool)
- func BuiltinHelpText(name string) string
- func BuiltinNames() []string
- func EmbeddedLanguageTags() []string
- func Eval(node ast.Node, env *object.Environment) object.Object
- func EvalInfixExpression(operator string, left, right object.Object) object.Object
- func EvalPrefixExpression(operator string, right object.Object) object.Object
- func ExecuteCallback(fnObj object.Object, args []object.Object) object.Object
- func ExtendFunctionEnv(fn *object.Function, args []object.Object, outer *object.Environment, ...) *object.Environment
- func FinalizeCallResult(result object.Object, node *ast.CallExpression, env *object.Environment) object.Object
- func HasBuiltin(name string) bool
- func InjectData(env *object.Environment, data map[string]interface{})
- func MatchPattern(pattern ast.Pattern, value object.Object, env *object.Environment) bool
- func RegisterBuiltins(group map[string]*object.Builtin)
- func RegisterEmbeddedLanguage(tag string, handler EmbeddedLanguageHandler) error
- func RegisterPluginBuiltins(group map[string]*object.Builtin)
- func RegisterStdModule(name, prefix string, builtinNames []string)
- func StartCLI()
- func StdModules() map[string]StdModuleInfo
- func ToNative(val object.Object) interface{}
- func ToObject(val interface{}) object.Object
- func UnwrapReturnValue(obj object.Object) object.Object
- type CLIOptions
- type EmbeddedLanguageContext
- type EmbeddedLanguageHandler
- type StdModuleInfo
Constants ¶
This section is empty.
Variables ¶
var ( // Builtins is the global map of registered builtin functions. These are // resolvable as bare identifiers by any script, with no import required. Builtins = map[string]*object.Builtin{} // PluginBuiltins holds functions registered by optional plugin packages // (pdf, rules, database, ...). Unlike Builtins, these are never resolved // as bare global identifiers by evalIdentifier — a script must import // the owning std module first (e.g. `import "rules" as rules;`) and // call them through that namespace (`rules.service()`). PluginBuiltins = map[string]*object.Builtin{} )
var ApplyFn func(object.Object, []object.Object, *object.Environment, *ast.CallExpression) object.Object
ApplyFn is an indirect reference to ApplyFunction, used by builtins to avoid init cycles.
var BuiltinHelpDescriptions = map[string]string{}/* 120 elements not displayed */
BuiltinHelpDescriptions provides human-readable help for builtins.
var BytecodeCompileFn func(program *ast.Program) (any, error)
BytecodeCompileFn compiles a *ast.Program to bytecode. If nil, the bytecode fast-path is disabled and the tree-walk evaluator is used for all statements.
var BytecodeIsUnsupportedErr func(err error) bool
BytecodeIsUnsupportedErr returns true when the error from BytecodeCompileFn indicates an unsupported AST node (meaning we should fall back to tree-walk).
var BytecodeRunFn func(compiled any, env *object.Environment) object.Object
BytecodeRunFn executes a compiled bytecode program. The first argument is the opaque value returned by BytecodeCompileFn.
DotExpressionHook is called for dot expressions on types not handled by the built-in dispatch. Return non-nil to use the result.
var ResolveImportPathFn func(importPath string, env *object.Environment) (string, error)
ResolveImportPathFn resolves a module import path. If nil, imports will fail.
ResolveStdModuleFn resolves virtual standard-library modules.
var RunFileFn func(filename string, args []string, opts CLIOptions)
RunFileFn is a hook that the root package can set to provide sandbox-aware file execution. If nil, StartCLI falls back to a basic evaluator.
var RunReplFn func(opts CLIOptions)
RunReplFn is a hook for the REPL. If nil, StartCLI uses a basic read-eval loop.
Functions ¶
func ApplyFunction ¶
func ApplyFunction(fn object.Object, args []object.Object, callerEnv *object.Environment, call *ast.CallExpression) object.Object
ApplyFunction calls a function object with the given arguments.
func BuiltinByName ¶
BuiltinByName looks up a builtin by name, checking the global (import-free) registry first and falling back to the plugin registry. Std-module export resolution relies on this fallback to reach plugin functions that are intentionally absent from Builtins.
func BuiltinHelpText ¶
BuiltinHelpText returns the help string for a named builtin.
func BuiltinNames ¶
func BuiltinNames() []string
BuiltinNames returns a sorted list of all registered builtin names.
func EmbeddedLanguageTags ¶
func EmbeddedLanguageTags() []string
func EvalInfixExpression ¶
EvalInfixExpression is the exported wrapper for evalInfixExpression, used by the bytecode VM.
func EvalPrefixExpression ¶
EvalPrefixExpression is the exported wrapper for evalPrefixExpression, used by the bytecode VM.
func ExecuteCallback ¶
ExecuteCallback invokes a function or builtin with args (exported wrapper).
func ExtendFunctionEnv ¶
func ExtendFunctionEnv(fn *object.Function, args []object.Object, outer *object.Environment, callExpr interface{}) *object.Environment
ExtendFunctionEnv is the exported version of extendFunctionEnv.
func FinalizeCallResult ¶
func FinalizeCallResult(result object.Object, node *ast.CallExpression, env *object.Environment) object.Object
FinalizeCallResult is the exported form of finalizeCallResult, used by the bytecode VM's OpCall handler so a call compiled through it accumulates call-stack frames on error exactly like the tree walker's evalCallExpression does (see the bytecode.FinalizeCallResultFn wiring in interpreter.go).
func HasBuiltin ¶
HasBuiltin reports whether a builtin with the given name is registered, either as a global builtin or as a plugin builtin reachable via import.
func InjectData ¶
func InjectData(env *object.Environment, data map[string]interface{})
func MatchPattern ¶
MatchPattern checks whether a value matches a pattern, binding variables into env on success.
func RegisterBuiltins ¶
RegisterBuiltins merges a group of builtins into the global registry.
func RegisterEmbeddedLanguage ¶
func RegisterEmbeddedLanguage(tag string, handler EmbeddedLanguageHandler) error
func RegisterPluginBuiltins ¶
RegisterPluginBuiltins merges a group of builtins into the plugin registry. Plugin builtins are only reachable through an explicit import of their owning std module (see presets_plugins.go), never as bare global identifiers — call this instead of RegisterBuiltins from a plugins/* package's init().
func RegisterStdModule ¶
RegisterStdModule records that a std/plugin module named name (e.g. "secretr", "pdf", "std/core") exports builtinNames (optionally stripped of prefix to form member names). It exists so static-analysis tooling (pkg/tooling) can recognize `import "<name>" as alias` without a hand-maintained, easily-stale duplicate of the module list - see RegisterStdModuleFn in the root interpreter package's RegisterStdBuiltinModuleWithPrefix, which calls this for every module it registers, keeping this registry automatically in sync.
func StdModules ¶
func StdModules() map[string]StdModuleInfo
StdModules returns a snapshot of every module registered via RegisterStdModule, keyed by module name.
Types ¶
type CLIOptions ¶
type CLIOptions struct {
Profile string
RequireOSIsolation bool
AllowInProcessFallback bool
AllowedCapabilities []string
AllowedExecCommands []string
AllowedNetworkHosts []string
AllowedDBDrivers []string
AllowedDBDSNPatterns []string
AllowedFileReadPaths []string
AllowedFileWritePaths []string
AllowedImportPaths []string
DeniedImportPaths []string
AllowedImportPackages []string
DeniedImportPackages []string
DenyDynamicImports bool
Timeout time.Duration
MaxDepth int
MaxSteps int64
MaxHeapMB int64
MaxSourceBytes int64
MaxStringBytes int64
MaxArrayLength int
MaxHashEntries int
MaxImportDepth int
MaxImportCount int
Data string
}
type EmbeddedLanguageContext ¶
type EmbeddedLanguageContext struct {
Tag string
Code string
Env *object.Environment
}
type EmbeddedLanguageHandler ¶
type EmbeddedLanguageHandler func(EmbeddedLanguageContext) object.Object
type StdModuleInfo ¶
StdModuleInfo mirrors a std/plugin module's registration: the prefix stripped from builtin names to form its members, and the full builtin names backing it.