exec

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: BSD-3-Clause Imports: 8 Imported by: 14

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 Save added in v0.5.0

func Save(context value.Context, file string)

Save writes the state of the workspace to the named file. The format of the output is ivy source text.

Output is written as source text, preserving the original precision of values when possible. Configuration is also saved. For ops, we can print the original source. Because binding of names to ops is lazy, the order we print ops is irrelevant.

Types

type Context

type Context struct {
	Stack []*value.Frame

	Globals map[string]*value.Var

	//  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 order of creation.
	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) ArgPrint added in v0.4.2

func (c *Context) ArgPrint(arg value.Expr) string

ArgPrint prints the value of an argument.

func (*Context) AssignGlobal added in v0.1.14

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

AssignGlobal assigns to the named global variable, creating it if needed.

func (*Context) Config

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

func (*Context) Define

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

Define installs the function in the Context after a little more error checking.

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) DisableTracing added in v0.5.0

func (c *Context) DisableTracing(t bool)

func (*Context) Errorf added in v0.4.2

func (c *Context) Errorf(format string, args ...interface{})

Errorf panics with the formatted string, with type Error.

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) FlushSavedParses added in v0.5.0

func (c *Context) FlushSavedParses()

FlushSavedParses clears all saved parses of ops in this context.

func (*Context) Global added in v0.1.14

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

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

func (*Context) IsLocal added in v0.5.0

func (c *Context) IsLocal(name string) bool

IsLocal reports whether the identifier names a defined local variable.

func (*Context) Local added in v0.1.14

func (c *Context) Local(name string) *value.Var

Local returns the Var descriptor for the named local variable, or nil if it is not present.

func (*Context) LocalPrint added in v0.4.2

func (c *Context) LocalPrint(name string) string

LocalPrint prints the value of a local variable.

func (*Context) LookupFn added in v0.4.1

func (c *Context) LookupFn(name string, isBinary bool) (int, bool)

LookupFn returns the index into the definition list for the function.

func (*Context) Pos added in v0.5.0

func (c *Context) Pos() value.Pos

func (*Context) RestoreOp added in v0.4.1

func (c *Context) RestoreOp(i int, fn *Function) bool

RestoreOp restores the argument function to the definition data structures, preserving its order in the definition list. Used by the parser to replace a function whose redefinition failed.

func (*Context) SetConstants

func (c *Context) SetConstants()

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

func (*Context) SetPos added in v0.5.0

func (c *Context) SetPos(file string, line, offset int)

func (*Context) StackTrace added in v0.4.2

func (c *Context) StackTrace()

StackTrace prints the execution stack. There may be conditions under which it will cause trouble by printing invalid values, but it tries to be safe.

func (*Context) TopOfStack added in v0.5.0

func (c *Context) TopOfStack() *value.Frame

func (*Context) TraceIndent added in v0.3.10

func (c *Context) TraceIndent() string

TraceIndent returns an indentation marker showing the depth of the stack.

func (*Context) UndefineAll added in v0.4.0

func (c *Context) UndefineAll(unary, binary, vars bool)

UndefineAll deletes all user-defined names of the types specified by the arguments, of which several may be set.

func (*Context) UndefineOp added in v0.4.0

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

UndefineOp removes the op with the given name and arity and reports whether it was present.

func (*Context) UndefineVar added in v0.4.0

func (c *Context) UndefineVar(name string) bool

UndefineVar removes the named variable and reports whether it was present.

func (*Context) UserDefined

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

type Function

type Function struct {
	IsBinary  bool
	Name      string
	Left      value.Expr
	Right     value.Expr
	Body      value.StatementList
	Variables []string // Names mentioned in the body that could be vars.
	Source    string
	HasRet    bool
	// At time of definition; needed to parse saved source correctly.
	Ibase int
}

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

Used for debugging. The output is not valid Ivy syntax.

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.

Jump to

Keyboard shortcuts

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