Documentation
¶
Index ¶
- func NewContext(conf *config.Config) value.Context
- func Predefined(op string) bool
- type Context
- func (c *Context) AssignGlobal(name string, val value.Value)
- func (c *Context) AssignLocal(i int, val value.Value)
- 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) Global(name string) value.Value
- func (c *Context) Local(i int) value.Value
- func (c *Context) SetConstants()
- func (c *Context) TraceIndent() string
- func (c *Context) Undefine(name string, binary bool)
- 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 { Globals Symtab // 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 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) AssignGlobal ¶ added in v0.1.14
AssignGlobal assigns the global variable the value. The variable must be defined either in the current function or globally. Inside a function, new variables become locals.
func (*Context) AssignLocal ¶ added in v0.1.14
AssignLocal assigns the local variable with the given index the value.
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) Global ¶ added in v0.1.14
Global returns the value of a global symbol, or nil if the symbol is not defined globally.
func (*Context) Local ¶ added in v0.1.14
Local returns the value of the local variable with index i.
func (*Context) SetConstants ¶
func (c *Context) SetConstants()
SetConstants re-assigns the fundamental constant values using the current setting of floating-point precision.
func (*Context) TraceIndent ¶ added in v0.3.10
TraceIndent returns an indentation marker showing the depth of the stack.
type Function ¶
type Function struct { IsBinary bool Name string Left value.Expr Right value.Expr Body []value.Expr Locals []string Globals []string }
Function represents a unary or binary user-defined operator.