Documentation ¶
Overview ¶
Package eval allows to evaluate s-expressions. Evaluation is splitted into parsing that s-expression and executing the result of the parsed expression. This is done to reduce syntax checks.
Index ¶
- Variables
- type Builtin
- type BuiltinA
- func (b BuiltinA) Call(eng *Engine, _ sxpf.Environment, args []sxpf.Object) (sxpf.Object, error)
- func (b BuiltinA) IsAtom() bool
- func (b BuiltinA) IsEql(other sxpf.Object) bool
- func (b BuiltinA) IsEqual(other sxpf.Object) bool
- func (b BuiltinA) IsNil() bool
- func (b BuiltinA) Name(eng *Engine) string
- func (b BuiltinA) Print(w io.Writer) (int, error)
- func (b BuiltinA) Repr() string
- func (b BuiltinA) String() string
- type BuiltinCallExpr
- type BuiltinEEA
- func (b BuiltinEEA) Call(eng *Engine, env sxpf.Environment, args []sxpf.Object) (sxpf.Object, error)
- func (b BuiltinEEA) IsAtom() bool
- func (b BuiltinEEA) IsEql(other sxpf.Object) bool
- func (b BuiltinEEA) IsEqual(other sxpf.Object) bool
- func (b BuiltinEEA) IsNil() bool
- func (b BuiltinEEA) Name(eng *Engine) string
- func (b BuiltinEEA) Print(w io.Writer) (int, error)
- func (b BuiltinEEA) Repr() string
- func (b BuiltinEEA) String() string
- type CallError
- type CallExpr
- type Callable
- type Engine
- func (eng *Engine) Bind(name string, obj sxpf.Object) error
- func (eng *Engine) BindBuiltinA(name string, fn BuiltinA) error
- func (eng *Engine) BindBuiltinEEA(name string, fn BuiltinEEA) error
- func (eng *Engine) BindSyntax(name string, fn SyntaxFn) error
- func (eng *Engine) BuiltinName(b Builtin) string
- func (eng *Engine) Call(env sxpf.Environment, fn Callable, args []sxpf.Object) (sxpf.Object, error)
- func (eng *Engine) Eval(env sxpf.Environment, obj sxpf.Object) (sxpf.Object, error)
- func (eng *Engine) Execute(env sxpf.Environment, expr Expr) (sxpf.Object, error)
- func (eng *Engine) ExecuteTCO(env sxpf.Environment, expr Expr) (sxpf.Object, error)
- func (eng *Engine) GetToplevelEnv() sxpf.Environment
- func (eng *Engine) Parse(env sxpf.Environment, obj sxpf.Object) (Expr, error)
- func (eng *Engine) RootEnvironment() sxpf.Environment
- func (eng *Engine) SetToplevelEnv(env sxpf.Environment) error
- func (eng *Engine) SymbolFactory() sxpf.SymbolFactory
- type Executor
- type Expr
- type NotBoundError
- type NotCallableError
- type Parser
- type ResolveExpr
- type SelfExpr
- type Syntax
- func (sy *Syntax) IsAtom() bool
- func (sy *Syntax) IsEql(other sxpf.Object) bool
- func (sy *Syntax) IsEqual(other sxpf.Object) bool
- func (sy *Syntax) IsNil() bool
- func (sy *Syntax) Parse(eng *Engine, env sxpf.Environment, args *sxpf.List) (Expr, error)
- func (sy *Syntax) Print(w io.Writer) (int, error)
- func (sy *Syntax) Repr() string
- func (sy *Syntax) String() string
- type SyntaxFn
Constants ¶
This section is empty.
Variables ¶
var FalseExpr = falseExpr{}
FalseExpr returns always False
var NilExpr = nilExpr{}
NilExpr returns always Nil
var TrueExpr = trueExpr{}
TrueExpr returns always True
Functions ¶
This section is empty.
Types ¶
type BuiltinA ¶
BuiltinA is the signature of all normal builtin functions.
type BuiltinCallExpr ¶
BuiltinCallExpr calls a builtin and returns the resulting object. It is an optimization of `CallExpr.`
func (*BuiltinCallExpr) Compute ¶
func (bce *BuiltinCallExpr) Compute(eng *Engine, env sxpf.Environment) (sxpf.Object, error)
func (*BuiltinCallExpr) String ¶
func (bce *BuiltinCallExpr) String() string
type BuiltinEEA ¶
BuiltinEEA is the signature of builtin functions that use all information, engine, environment, and arguments.
func (BuiltinEEA) Call ¶
func (b BuiltinEEA) Call(eng *Engine, env sxpf.Environment, args []sxpf.Object) (sxpf.Object, error)
Call the builtin function.
func (BuiltinEEA) IsAtom ¶
func (b BuiltinEEA) IsAtom() bool
func (BuiltinEEA) IsNil ¶
func (b BuiltinEEA) IsNil() bool
func (BuiltinEEA) Name ¶
func (b BuiltinEEA) Name(eng *Engine) string
func (BuiltinEEA) Repr ¶
func (b BuiltinEEA) Repr() string
func (BuiltinEEA) String ¶
func (b BuiltinEEA) String() string
type CallExpr ¶
CallExpr calls a procedure and returns the resulting objects.
type Callable ¶
type Callable interface { // Call the value with the given args and environment. Call(*Engine, sxpf.Environment, []sxpf.Object) (sxpf.Object, error) }
Callable is a value that can be called for evaluation.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the collection of all relevant data element to execute / evaluate an object.
func MakeEngine ¶
func MakeEngine(sf sxpf.SymbolFactory, root sxpf.Environment, parser Parser, executor Executor) *Engine
MakeEngine creates a new engine.
func (*Engine) Bind ¶
Bind a given object to a symbol of the given name in the engine's root environment.
func (*Engine) BindBuiltinA ¶
BindBuiltinA binds a standard builtin function to the given name in the engine's root environment.
func (*Engine) BindBuiltinEEA ¶
func (eng *Engine) BindBuiltinEEA(name string, fn BuiltinEEA) error
BindBuiltinEEA binds a special builtin function to the given name in the engine's root environment.
func (*Engine) BindSyntax ¶
BindSyntax binds a syntax parser to the given name in the engine's root environment. It also binds the parser to the symbol directly.
func (*Engine) BuiltinName ¶
BuiltinName returns the name of the given Builtin.
func (*Engine) ExecuteTCO ¶
ExecuteTCO the given expression in the given environment, but tail-call optimized.
func (*Engine) GetToplevelEnv ¶
func (eng *Engine) GetToplevelEnv() sxpf.Environment
GetToplevelEnv returns the current top-level environment.
func (*Engine) RootEnvironment ¶
func (eng *Engine) RootEnvironment() sxpf.Environment
RootEnvironment returns the root environment of the engine.
func (*Engine) SetToplevelEnv ¶
func (eng *Engine) SetToplevelEnv(env sxpf.Environment) error
SetToplevelEnv sets the given environment as the top-level environment. It must be the root environment or a child of it.
func (*Engine) SymbolFactory ¶
func (eng *Engine) SymbolFactory() sxpf.SymbolFactory
SymbolFactory returns the symbol factory of the engine.
type Executor ¶
type Executor interface { // Execute the expression in an environment and return the result. // It may have side-effects, on the given environment, or on the // general environment of the system. Execute(*Engine, sxpf.Environment, Expr) (sxpf.Object, error) }
Executor is about controlling the execution of expressions. Do not call the method `Expr.Execute` directly, call the executor to do this.
func MakeSimpleExecutor ¶
func MakeSimpleExecutor() Executor
MakeSimpleExecutor creates a new executor which just executes expressions.
type Expr ¶
type Expr interface { // Compute the expression in an environment and return the result. // It may have side-effects, on the given environment, or on the // general environment of the system. Compute(*Engine, sxpf.Environment) (sxpf.Object, error) }
Expr are values that are executed for evaluation in an environment.
type NotBoundError ¶
type NotBoundError struct { Env sxpf.Environment Sym *sxpf.Symbol }
NotBoundError signals that a symbol was not found in an environment.
func (NotBoundError) Error ¶
func (e NotBoundError) Error() string
type NotCallableError ¶
NotCallableError signals that a value cannot be called when it must be called.
func (NotCallableError) Error ¶
func (e NotCallableError) Error() string
func (NotCallableError) String ¶
func (e NotCallableError) String() string
type Parser ¶
Parser transform an object into an executable expression.
func MakeDefaultParser ¶
func MakeDefaultParser() Parser
MakeDefaultParser creates a new default parser.
type ResolveExpr ¶
ResolveExpr resolves the given symbol in an environment and returns the value.
func (ResolveExpr) Compute ¶
func (re ResolveExpr) Compute(_ *Engine, env sxpf.Environment) (sxpf.Object, error)
type Syntax ¶
type Syntax struct {
// contains filtered or unexported fields
}
Syntax represents all syntax constructing functions implemented in Go.
func MakeSyntax ¶
MakeSyntax creates a new special function.