Documentation ¶
Index ¶
- Variables
- func NewContext(conf *config.Config) value.Context
- type Context
- func (c *Context) Assign(name string, val value.Value)
- func (c *Context) Config() *config.Config
- func (c *Context) Declare(name string)
- func (c *Context) Define(fn *Function)
- func (c *Context) Defined(op string) bool
- func (c *Context) DefinedBinary(op string) bool
- func (c *Context) DefinedUnary(op string) bool
- func (c *Context) Eval(exprs []value.Expr) []value.Value
- func (c *Context) EvalBinary(left value.Value, op string, right value.Value) value.Value
- func (c *Context) EvalUnary(op string, right value.Value) value.Value
- func (c *Context) ForgetAll()
- func (c *Context) Lookup(name string) value.Value
- func (c *Context) SetConstants()
- func (c *Context) UserDefined(op string, isBinary bool) bool
- type Function
- type OpDef
- type Symtab
Constants ¶
This section is empty.
Variables ¶
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.
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.
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 ¶
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 ¶
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) Define ¶
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 ¶
DefinedBinary reports whether the operator is a known binary.
func (*Context) DefinedUnary ¶
DefinedUnary reports whether the operator is a known unary.
func (*Context) EvalBinary ¶
EvalBinary evaluates a binary operator.
func (*Context) SetConstants ¶
func (c *Context) SetConstants()
SetConstants re-assigns the fundamental constant values using the current setting of floating-point precision.