exec

package
v0.0.0-...-e696326 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2016 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsBinary = map[string]bool{
	"!=":     true,
	"&":      true,
	"*":      true,
	"**":     true,
	"+":      true,
	",":      true,
	"-":      true,
	"/":      true,
	"<":      true,
	"<<":     true,
	"<=":     true,
	"==":     true,
	">":      true,
	">=":     true,
	">>":     true,
	"[]":     true,
	"^":      true,
	"and":    true,
	"decode": true,
	"div":    true,
	"drop":   true,
	"encode": true,
	"fill":   true,
	"idiv":   true,
	"imod":   true,
	"in":     true,
	"iota":   true,
	"log":    true,
	"max":    true,
	"min":    true,
	"mod":    true,
	"nand":   true,
	"nor":    true,
	"or":     true,
	"rho":    true,
	"rot":    true,
	"sel":    true,
	"take":   true,
	"xor":    true,
	"|":      true,
}

IsBinary identifies the binary operators; these can be used in reductions.

View Source
var IsUnary = map[string]bool{
	"**":    true,
	"+":     true,
	",":     true,
	"-":     true,
	"/":     true,
	"?":     true,
	"^":     true,
	"abs":   true,
	"acos":  true,
	"asin":  true,
	"atan":  true,
	"ceil":  true,
	"char":  true,
	"code":  true,
	"cos":   true,
	"down":  true,
	"flip":  true,
	"float": true,
	"floor": true,
	"iota":  true,
	"ivy":   true,
	"log":   true,
	"not":   true,
	"rev":   true,
	"rho":   true,
	"sgn":   true,
	"sin":   true,
	"sqrt":  true,
	"tan":   true,
	"text":  true,
	"up":    true,
}

IsUnary identifies the binary operators; these can be used in reductions.

View Source
var OperatorWord = map[string]bool{
	"abs":    true,
	"acos":   true,
	"and":    true,
	"asin":   true,
	"atan":   true,
	"ceil":   true,
	"char":   true,
	"code":   true,
	"cos":    true,
	"decode": true,
	"div":    true,
	"down":   true,
	"drop":   true,
	"encode": true,
	"fill":   true,
	"flip":   true,
	"float":  true,
	"floor":  true,
	"grade":  true,
	"idiv":   true,
	"imod":   true,
	"in":     true,
	"iota":   true,
	"ivy":    true,
	"log":    true,
	"max":    true,
	"min":    true,
	"mod":    true,
	"nand":   true,
	"nor":    true,
	"not":    true,
	"or":     true,
	"rev":    true,
	"rho":    true,
	"rot":    true,
	"sel":    true,
	"sgn":    true,
	"sin":    true,
	"sqrt":   true,
	"take":   true,
	"tan":    true,
	"text":   true,
	"up":     true,
	"xor":    true,
}

Note: All operators are not valid hexadecimal constants, so they work when base is 16. Higher bases are less critical.

Functions

func NewContext

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

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

Types

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

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

Defined reports whether the operator is known.

func (*Context) DefinedBinary

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

DefinedBinary reports whether the operator is a known binary.

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.

func (*Context) EvalUnary

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

EvalUnary evaluates a unary operator.

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