eval

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 24 Imported by: 28

Documentation

Overview

Package eval implements the tree-walking evaluator for the interpreter.

Index

Constants

This section is empty.

Variables

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

ApplyFn is an indirect reference to ApplyFunction, used by builtins to avoid init cycles.

View Source
var BuiltinHelpDescriptions = map[string]string{}/* 120 elements not displayed */

BuiltinHelpDescriptions provides human-readable help for builtins.

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

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

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

View Source
var DotExpressionHook func(left object.Object, name string) object.Object

DotExpressionHook is called for dot expressions on types not handled by the built-in dispatch. Return non-nil to use the result.

View Source
var ResolveImportPathFn func(importPath string, env *object.Environment) (string, error)

ResolveImportPathFn resolves a module import path. If nil, imports will fail.

View Source
var ResolveStdModuleFn func(importPath string) (map[string]object.Object, bool)

ResolveStdModuleFn resolves virtual standard-library modules.

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

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

func BuiltinByName(name string) (*object.Builtin, bool)

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

func BuiltinHelpText(name string) string

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 Eval

func Eval(node ast.Node, env *object.Environment) object.Object

Eval evaluates an AST node in the given environment.

func EvalInfixExpression

func EvalInfixExpression(operator string, left, right object.Object) object.Object

EvalInfixExpression is the exported wrapper for evalInfixExpression, used by the bytecode VM.

func EvalPrefixExpression

func EvalPrefixExpression(operator string, right object.Object) object.Object

EvalPrefixExpression is the exported wrapper for evalPrefixExpression, used by the bytecode VM.

func ExecuteCallback

func ExecuteCallback(fnObj object.Object, args []object.Object) object.Object

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

func HasBuiltin(name string) bool

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

func MatchPattern(pattern ast.Pattern, value object.Object, env *object.Environment) bool

MatchPattern checks whether a value matches a pattern, binding variables into env on success.

func RegisterBuiltins

func RegisterBuiltins(group map[string]*object.Builtin)

RegisterBuiltins merges a group of builtins into the global registry.

func RegisterEmbeddedLanguage

func RegisterEmbeddedLanguage(tag string, handler EmbeddedLanguageHandler) error

func RegisterPluginBuiltins

func RegisterPluginBuiltins(group map[string]*object.Builtin)

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

func RegisterStdModule(name, prefix string, builtinNames []string)

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 StartCLI

func StartCLI()

StartCLI parses CLI flags and runs the interpreter.

func StdModules

func StdModules() map[string]StdModuleInfo

StdModules returns a snapshot of every module registered via RegisterStdModule, keyed by module name.

func ToNative

func ToNative(val object.Object) interface{}

ToNative converts an SPL value into the ordinary Go representation consumed by conversion, serialization, and embedding libraries.

func ToObject

func ToObject(val interface{}) object.Object

func UnwrapReturnValue

func UnwrapReturnValue(obj object.Object) object.Object

UnwrapReturnValue is the exported version of unwrapReturnValue.

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

type StdModuleInfo struct {
	Prefix       string
	BuiltinNames []string
}

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.

Jump to

Keyboard shortcuts

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