Documentation
¶
Index ¶
- func NewContext(conf *config.Config) value.Context
- func Save(context value.Context, file string)
- type Context
- func (c *Context) ArgPrint(arg value.Expr) string
- func (c *Context) AssignGlobal(name string, val value.Value)
- func (c *Context) Config() *config.Config
- 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) DisableTracing(t bool)
- func (c *Context) Errorf(format string, args ...interface{})
- 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) FlushSavedParses()
- func (c *Context) Global(name string) *value.Var
- func (c *Context) IsLocal(name string) bool
- func (c *Context) Local(name string) *value.Var
- func (c *Context) LocalPrint(name string) string
- func (c *Context) LookupFn(name string, isBinary bool) (int, bool)
- func (c *Context) Pos() value.Pos
- func (c *Context) RestoreOp(i int, fn *Function) bool
- func (c *Context) SetConstants()
- func (c *Context) SetPos(file string, line, offset int)
- func (c *Context) StackTrace()
- func (c *Context) TopOfStack() *value.Frame
- func (c *Context) TraceIndent() string
- func (c *Context) UndefineAll(unary, binary, vars bool)
- func (c *Context) UndefineOp(name string, binary bool) bool
- func (c *Context) UndefineVar(name string) bool
- func (c *Context) UserDefined(op string, isBinary bool) bool
- type Function
- type OpDef
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 Save ¶ added in v0.5.0
Save writes the state of the workspace to the named file. The format of the output is ivy source text.
Output is written as source text, preserving the original precision of values when possible. Configuration is also saved. For ops, we can print the original source. Because binding of names to ops is lazy, the order we print ops is irrelevant.
Types ¶
type Context ¶
type Context struct {
Stack []*value.Frame
Globals map[string]*value.Var
// 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 order of creation.
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 to the named global variable, creating it if needed.
func (*Context) Define ¶
Define installs the function in the Context after a little more error checking.
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) DisableTracing ¶ added in v0.5.0
func (*Context) EvalBinary ¶
EvalBinary evaluates a binary operator, including products.
func (*Context) FlushSavedParses ¶ added in v0.5.0
func (c *Context) FlushSavedParses()
FlushSavedParses clears all saved parses of ops in this context.
func (*Context) Global ¶ added in v0.1.14
Global returns a global variable, or nil if the symbol is not defined globally.
func (*Context) IsLocal ¶ added in v0.5.0
IsLocal reports whether the identifier names a defined local variable.
func (*Context) Local ¶ added in v0.1.14
Local returns the Var descriptor for the named local variable, or nil if it is not present.
func (*Context) LocalPrint ¶ added in v0.4.2
LocalPrint prints the value of a local variable.
func (*Context) LookupFn ¶ added in v0.4.1
LookupFn returns the index into the definition list for the function.
func (*Context) RestoreOp ¶ added in v0.4.1
RestoreOp restores the argument function to the definition data structures, preserving its order in the definition list. Used by the parser to replace a function whose redefinition failed.
func (*Context) SetConstants ¶
func (c *Context) SetConstants()
SetConstants re-assigns the fundamental constant values using the current setting of floating-point precision.
func (*Context) StackTrace ¶ added in v0.4.2
func (c *Context) StackTrace()
StackTrace prints the execution stack. There may be conditions under which it will cause trouble by printing invalid values, but it tries to be safe.
func (*Context) TopOfStack ¶ added in v0.5.0
func (*Context) TraceIndent ¶ added in v0.3.10
TraceIndent returns an indentation marker showing the depth of the stack.
func (*Context) UndefineAll ¶ added in v0.4.0
UndefineAll deletes all user-defined names of the types specified by the arguments, of which several may be set.
func (*Context) UndefineOp ¶ added in v0.4.0
UndefineOp removes the op with the given name and arity and reports whether it was present.
func (*Context) UndefineVar ¶ added in v0.4.0
UndefineVar removes the named variable and reports whether it was present.
type Function ¶
type Function struct {
IsBinary bool
Name string
Left value.Expr
Right value.Expr
Body value.StatementList
Variables []string // Names mentioned in the body that could be vars.
Source string
HasRet bool
// At time of definition; needed to parse saved source correctly.
Ibase int
}
Function represents a unary or binary user-defined operator.