Back to godoc.org
robpike.io/ivy/exec

package exec

v0.0.0 (e5a40e4)
Latest Go to latest
Published: Mar 29, 2020 | License: BSD-3-Clause | Module: robpike.io/ivy

Index

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.

type Context

type Context struct {

	// Stack is a stack of symbol tables, one entry per function (op) invocation,
	// plus the 0th one at the base.
	Stack []Symtab
	//  UnaryFn maps the names of unary functions (ops) to their implemenations.
	UnaryFn map[string]*Function
	//  BinaryFn maps the names of binary functions (ops) to their implemenations.
	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) Assign

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

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

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) Lookup

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

Lookup returns the value of a symbol.

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) 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
}

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.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier