exec

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: BSD-3-Clause Imports: 4 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(conf *config.Config) value.Context

NewContext returns a new execution context: the stack and variables, plus the execution configuration.

func Predefined

func Predefined(op string) bool

Predefined reports whether the operator is predefined, a built-in.

Types

type Context

type Context struct {
	Globals Symtab

	//  UnaryFn maps the names of unary functions (ops) to their implementations.
	UnaryFn map[string]*Function
	//  BinaryFn maps the names of binary functions (ops) to their implementations.
	BinaryFn map[string]*Function
	// Defs is a list of defined ops, in time order.  It is used when saving the
	// Context to a file.
	Defs []OpDef
	// contains filtered or unexported fields
}

Context holds execution context, specifically the binding of names to values and operators. It is the only implementation of ../value/Context, but since it references the value package, there would be a cycle if that package depended on this type definition.

func (*Context) AssignGlobal added in v0.1.14

func (c *Context) AssignGlobal(name string, val value.Value)

Assign assigns the global variable the value. The variable must be defined either in the current function or globally. Inside a function, new variables become locals.

func (*Context) AssignLocal added in v0.1.14

func (c *Context) AssignLocal(i int, val value.Value)

AssignLocal assigns the local variable with the given index the value.

func (*Context) Binary

func (c *Context) Binary(op string) value.BinaryOp

func (*Context) Config

func (c *Context) Config() *config.Config

func (*Context) Declare

func (c *Context) Declare(name string)

Declare makes the name a variable while parsing the next function.

func (*Context) Define

func (c *Context) Define(fn *Function)

Define defines the function and installs it. It also performs some error checking and adds the function to the sequencing information used by the save method.

func (*Context) DefinedBinary

func (c *Context) DefinedBinary(op string) bool

DefinedBinary reports whether the operator is a known binary.

func (*Context) DefinedOp

func (c *Context) DefinedOp(op string) bool

DefinedOp reports whether the operator is known.

func (*Context) DefinedUnary

func (c *Context) DefinedUnary(op string) bool

DefinedUnary reports whether the operator is a known unary.

func (*Context) Eval

func (c *Context) Eval(exprs []value.Expr) []value.Value

Eval evaluates a list of expressions.

func (*Context) EvalBinary

func (c *Context) EvalBinary(left value.Value, op string, right value.Value) value.Value

EvalBinary evaluates a binary operator, including products.

func (*Context) EvalUnary

func (c *Context) EvalUnary(op string, right value.Value) value.Value

EvalUnary evaluates a unary operator, including reductions and scans.

func (*Context) ForgetAll

func (c *Context) ForgetAll()

ForgetAll forgets the declared variables.

func (*Context) Global added in v0.1.14

func (c *Context) Global(name string) value.Value

Global returns the value of a global symbol, or nil if the symbol is not defined globally.

func (*Context) Local added in v0.1.14

func (c *Context) Local(i int) value.Value

Local returns the value of the local variable with index i.

func (*Context) SetConstants

func (c *Context) SetConstants()

SetConstants re-assigns the fundamental constant values using the current setting of floating-point precision.

func (*Context) Unary

func (c *Context) Unary(op string) value.UnaryOp

func (*Context) Undefine added in v0.3.1

func (c *Context) Undefine(name string, binary bool)

func (*Context) UserDefined

func (c *Context) UserDefined(op string, isBinary bool) bool

type Function

type Function struct {
	IsBinary bool
	Name     string
	Left     string
	Right    string
	Body     []value.Expr
	Locals   []string
	Globals  []string
}

Function represents a unary or binary user-defined operator.

func (*Function) EvalBinary

func (fn *Function) EvalBinary(context value.Context, left, right value.Value) value.Value

func (*Function) EvalUnary

func (fn *Function) EvalUnary(context value.Context, right value.Value) value.Value

func (*Function) String

func (fn *Function) String() string

type OpDef

type OpDef struct {
	Name     string
	IsBinary bool
}

OpDef is just a record of an op's name and arg count. It is held in execContext.defs to control writing the ops out in the right order during save. See comment above.

type Symtab

type Symtab map[string]value.Value

Symtab is a symbol table, a map of names to values.

Jump to

Keyboard shortcuts

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