evaluator

package
v0.17.8 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxCallDepth = 1000

DefaultMaxCallDepth is the default maximum call depth (1000)

Variables

View Source
var (
	NULL  = &object.Null{}
	TRUE  = object.NewBoolean(true)
	FALSE = object.NewBoolean(false)
)

Functions

func ApplyFunctionGIL added in v0.15.0

func ApplyFunctionGIL(ctx context.Context, fn object.Object, args []object.Object, keywords map[string]object.Object, env *object.Environment) object.Object

applyFunction calls a function object with arguments and keyword arguments.

It is unexported because it does NOT acquire the interpreter lock: it is the internal dispatch used while the lock is already held (dunder-method dispatch, recursion, etc.). The locking boundaries are EvalWithContext, ApplyFunctionGIL, and the evaliface adapter (CallFunction/CallObjectFunction/CallMethod). Go callers outside the evaluator package must use ApplyFunctionGIL.

ApplyFunctionGIL acquires the environment's interpreter lock (reentrant via goroutine-id ownership, so nested calls from the same goroutine don't deadlock) and then dispatches via applyFunction. Host code that calls script functions — especially concurrently against a shared environment — must use this rather than the unexported applyFunction, which assumes the lock is held.

func ContextWithCallDepth

func ContextWithCallDepth(ctx context.Context, maxDepth int) context.Context

ContextWithCallDepth creates a context with a call depth tracker

func ContextWithSourceFile

func ContextWithSourceFile(ctx context.Context, filename string) context.Context

ContextWithSourceFile creates a context with source file info for error reporting

func Eval

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

Eval executes without context (backwards compatible)

func EvalWithContext

func EvalWithContext(ctx context.Context, node ast.Node, env *object.Environment) object.Object

EvalWithContext executes with context for timeout/cancellation

func GetEnvFromContext

func GetEnvFromContext(ctx context.Context) *object.Environment

GetEnvFromContext retrieves environment from context for external functions

func GetImportBuiltin

func GetImportBuiltin() *object.Builtin

func GetSourceFileFromContext

func GetSourceFileFromContext(ctx context.Context) string

GetSourceFileFromContext retrieves source file name from context

func SetCallDepthInContext

func SetCallDepthInContext(ctx context.Context, cd *CallDepth) context.Context

SetCallDepthInContext stores call depth tracker in context

func SetEnvInContext

func SetEnvInContext(ctx context.Context, env *object.Environment) context.Context

SetEnvInContext stores environment in context for builtin functions

func WithEvaluator

func WithEvaluator(ctx context.Context) context.Context

WithEvaluator adds evaluator to context

Types

type CallDepth

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

CallDepth tracks function call depth to prevent stack overflow

func GetCallDepthFromContext

func GetCallDepthFromContext(ctx context.Context) *CallDepth

GetCallDepthFromContext retrieves call depth tracker from context

func NewCallDepth

func NewCallDepth(maxDepth int) *CallDepth

NewCallDepth creates a new CallDepth tracker with the specified max depth

func (*CallDepth) Depth

func (cd *CallDepth) Depth() int

Depth returns current call depth

func (*CallDepth) Enter

func (cd *CallDepth) Enter() bool

Enter increments call depth and returns true if within limits

func (*CallDepth) Exit

func (cd *CallDepth) Exit()

Exit decrements call depth

Jump to

Keyboard shortcuts

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