Documentation ¶
Index ¶
- func NewContext(conf *config.Config) value.Context
- func Predefined(op string) bool
- type Context
- func (c *Context) Assign(name string, val value.Value)
- func (c *Context) Binary(op string) value.BinaryOp
- func (c *Context) Config() *config.Config
- func (c *Context) Declare(name string)
- func (c *Context) Define(fn *Function)
- func (c *Context) DefinedBinary(op string) bool
- func (c *Context) DefinedOp(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) Unary(op string) value.UnaryOp
- func (c *Context) UserDefined(op string, isBinary bool) bool
- type Function
- type OpDef
- type Symtab
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewContext ¶
NewContext returns a new execution context: the stack and variables, plus the execution configuration.
func Predefined ¶
Predefined reports whether the operator is predefined, a built-in.
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, including products.
func (*Context) SetConstants ¶
func (c *Context) SetConstants()
SetConstants re-assigns the fundamental constant values using the current setting of floating-point precision.
type Function ¶
Function represents a unary or binary user-defined operator.