[][src]Module wlambda::compiler

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

CompileEnv

Compile time environment for allocating and storing variables inside a function scope.

EvalContext

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:

GlobalEnv

Holds global environment variables.

LocalFileModuleResolver

This structure implements the ModuleResolver trait and is responsible for loading modules on !@import for WLambda.

SymbolTable

Stores symbols and values for a WLambda module that can be added to a GlobalEnv with set_module.

Enums

ArityParam
EvalError

Errors that can occur when evaluating a piece of WLambda code. Usually created by methods of EvalContext.

ModuleLoadError

Error for the ModuleResolver trait, to implement custom module loading behaviour.

ResPos
ResValue

Traits

ModuleResolver

This trait is responsible for loading modules and returning a collection of name->value mappings for a module name.

Functions

check_for_at_arity
copy_upvs
eval

Evaluates a piece of WLambda code in a default global environment.

fetch_object_key_access
set_impl_arity

Type Definitions

GlobalEnvRef

Reference type of GlobalEnv.