context

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package context maintains the namespaces and stack for the interpreter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

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

Context of an evaluation while running the interpreter. It contains the current frame stack, values of variables, and the evaluator to execute operations.

func (*Context) Core

func (ctx *Context) Core() *Core

Core context used by this context.

func (*Context) CurrentFrame

func (ctx *Context) CurrentFrame() *Frame

CurrentFrame returns the current frame.

func (*Context) CurrentFunc

func (ctx *Context) CurrentFunc() ir.Func

CurrentFunc returns the current function being run.

func (*Context) File

func (ctx *Context) File() *ir.File

File returns the current file the interpreter is running code from.

func (*Context) PopFrame

func (ctx *Context) PopFrame()

PopFrame pops the current frame from the stack.

func (*Context) PushBlockFrame

func (ctx *Context) PushBlockFrame() *Frame

PushBlockFrame pushes an empty new frame on the stack.

func (*Context) PushFuncFrame

func (ctx *Context) PushFuncFrame(fn ir.Func) (*Frame, error)

PushFuncFrame pushes a function frame to the stack.

func (*Context) String

func (ctx *Context) String() string

func (*Context) Sub

func (ctx *Context) Sub(elts map[string]ir.Element) *Context

Sub returns a child context given a set of elements.

type Core

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

Core contains everything in the context independent of code location.

func New

func New(interp Interpreter, importer ir.Importer) (*Core, error)

New returns a new interpreter context.

func (*Core) NewFileContext

func (core *Core) NewFileContext(file *ir.File) (*Context, error)

NewFileContext returns a context for a given file.

type Frame

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

Frame in the context.

func (*Frame) Assign

func (fr *Frame) Assign(name string, value ir.Element) error

Assign a value to an existing name in the frame owning the value.

func (*Frame) Define

func (fr *Frame) Define(name string, value ir.Element)

Define a new variable in the frame.

func (*Frame) Find

func (fr *Frame) Find(id *ast.Ident) (ir.Element, error)

Find the element in the stack of frame given its identifier.

type Interpreter

type Interpreter interface {
	// InitPkgScope initialises the namespace of a package.
	InitPkgScope(pkg *ir.Package, scope *scope.RWScope[ir.Element]) (ir.Element, error)

	// InitBuiltins initialises a namespace with GX builtins implementation.
	InitBuiltins(ctx *Context, scope *scope.RWScope[ir.Element]) error
}

Interpreter evaluates expressions and statements given the context.

Jump to

Keyboard shortcuts

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