Expand description
Implements all the semantics of WLambda. It takes an AST that was generated by the parser and compiles it to a tree of closures.
The compiler and the runtime require multiple
other data structures, such as GlobalEnv
with a
SymbolTable
for global functions,
a ModuleResolver
and a ThreadCreator
.
An to execute the closures that the compiler generated
you need an Env
instance (which itself requires a reference
to the GlobalEnv
.
To orchestrate all this the EvalContext
exists.
You can customize:
- The
GlobalEnv
with custom globals and even with your own core and standard library functions - You can provide a custom
ModuleResolver
, which loads the modules from other sources (eg. memory or network). - You can make your own
ThreadCreator
, to customize thread creation.
However, to get some WLambda code running quickly there is
EvalContext::new_default()
which creates a ready made context for
evaluating WLambda code:
use wlambda::*;
let mut ctx = EvalContext::new_default();
let res = ctx.eval("$[10, 20 + 30]").unwrap();
assert_eq!(res.s(), "$[10,50]");
Structs§
- Eval
Context - This context holds all the data to compile and execute a piece of WLambda code. You can either use the default environment, or customize the EvalContext to your application’s needs. You can provide custom:
- Global
Env - Holds global environment variables.
- Local
File Module Resolver - This structure implements the ModuleResolver trait and is
responsible for loading modules on
!@import
for WLambda. - Symbol
Table - Stores symbols and values for a WLambda module that can be added to a
GlobalEnv
withset_module
.
Enums§
- Eval
Error - Errors that can occur when evaluating a piece of WLambda code.
Usually created by methods of
EvalContext
. - Module
Load Error - Error for the
ModuleResolver
trait, to implement custom module loading behaviour.
Traits§
- Module
Resolver - This trait is responsible for loading modules and returning a collection of name->value mappings for a module name.
Functions§
- test_
eval_ to_ string - This is a function to help evaluating a piece of WLambda code and receive a text representation of the result. It’s primarily used by the WLambda test suite.
Type Aliases§
- Global
EnvRef - Reference type of
GlobalEnv
.