evaluator

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Overview

Package evaluator defines interfaces for the interpreter to use to evaluate GX code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	elements.FileContext

	// Evaluation returns the context in which the evaluation is done.
	Evaluation() EvaluationContext

	// Sub returns a new context with additional variables being defined.
	Sub(map[string]elements.Element) (Context, error)

	// EvalFunctionToElement evaluates a function literal into an interpreter element.
	EvalFunctionToElement(eval Evaluator, fn ir.Func, args []elements.Element) ([]elements.Element, error)
}

Context in which an operator is being executed.

type EvaluationContext

type EvaluationContext interface {
	// NewFileContext returns a context for a given file.
	NewFileContext(*ir.File) (Context, error)

	// Evaluator returns the evaluator used by the interpreter.
	Evaluator() Evaluator
}

EvaluationContext is the global state in which an evaluator runs.

type Evaluator

type Evaluator interface {
	// NewFunc creates a new function given its definition and a receiver.
	NewFunc(fn ir.Func, recv *elements.Receiver) elements.Func

	// NewSub returns a new evaluator given a new array operator implementations.
	NewSub(elements.ArrayOps) Evaluator

	// Importer returns an importer to import package.
	Importer() Importer

	// ArrayOps returns the operator implementations for arrays.
	ArrayOps() elements.ArrayOps

	// Processor returns the used by the array evaluator.
	Processor() *processor.Processor

	// ElementFromAtom returns an element from an atomic GX value.
	ElementFromAtom(src elements.ExprAt, val values.Array) (elements.NumericalElement, error)

	// CallFuncLit calls a function literal.
	CallFuncLit(ctx Context, ref *ir.FuncLit, args []elements.Element) ([]elements.Element, error)

	// Trace register a call to the trace builtin function.
	Trace(call elements.CallAt, fn elements.Func, irFunc *ir.FuncBuiltin, args []elements.Element, fc *elements.InputValues) error
}

Evaluator implements GX operators.

type Importer

type Importer interface {
	// Import a package given its path.
	Import(pkgPath string) (*ir.Package, error)
}

Importer imports packages given their path.

Jump to

Keyboard shortcuts

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