Expand description
§Scheme Evaluator
An R7RS-compliant Scheme evaluator with fully trampolined evaluation - no Rust stack recursion, enabling unlimited recursion depth (bounded only by heap/arena size).
§Key Features
- Full Trampolining: All evaluation uses continuation-passing style with an explicit continuation stack. No Rust recursion means no stack overflow.
- Strict Evaluation: Call-by-value semantics - all arguments are evaluated before function application
- Proper TCO: Tail calls reuse the same continuation frame
- Lexically Scoped Closures: First-class functions with captured environments
- Rich Error Handling: Error messages with stack traces
- Pattern Matching:
casefor value matching - Iteration:
doloops for imperative-style iteration - Meta-programming:
evalfor runtime code evaluation,quasiquote/unquote - Mutation:
set!,set-car!,set-cdr!for imperative programming - Pluggable I/O: Accepts any
IoProviderat runtime for port operations (display,read,write, string ports, etc.) without breakingno_stdcompatibility - Native FFI: Register Rust functions callable from Scheme via
NativeRegistryand theFromLisp/ToLispconversion traits
§Evaluation Strategy
This evaluator uses strict (call-by-value) evaluation:
- All function arguments are fully evaluated before the function is called
- This provides predictable evaluation order and side-effect timing
- Tail call optimization is supported for constant-space recursion
§Mutation
This Lisp supports mutation operations for imperative programming:
set!- Mutate a variable bindingset-car!- Mutate the car of a cons cellset-cdr!- Mutate the cdr of a cons cell
Note: Mutation breaks referential transparency but enables imperative patterns.
§Truthiness
Only #f is false. Everything else (including the empty list '()) is truthy.
§Special Forms
quote- Return expression unevaluatedif- Conditionalcond- Multi-way conditionalcase- Pattern matching on valueslambda- Create closuredefine- Define variable/functionset!- Mutate variable bindinglet- Local bindinglet*- Sequential local bindingbegin- Sequence of expressionsand/or- Short-circuit boolean operationsdo- Iteration with initialization and step expressionsquasiquote- Template withunquoteandunquote-splicingeval- Evaluate expression at runtimeapply- Apply function to argument listvalues- Return multiple values as a list
Re-exports§
pub use native::FromLisp;pub use native::ToLisp;pub use native::NativeRegistry;pub use native::NativeEntry;pub use native::NativeFn;pub use native::extract_arg;pub use native::args_empty;pub use native::count_args;pub use native::MAX_NATIVE_FUNCTIONS;
Modules§
- native
- Native Function Interop
Macros§
- binary_
div_ op - Macro for binary division operations with zero check.
- binary_
int_ cmp - Macro for binary numeric comparison (returns boolean).
- binary_
int_ op - Macro for binary numeric arithmetic (returns number).
- builtin_
char_ to_ int - Macro for unary char-to-integer conversion.
- builtin_
char_ transform - Macro for unary character transformation.
- builtin_
div_ op - Macro for binary integer operations with division-by-zero check.
- builtin_
numeric_ pred - Macro for numeric predicate builtins.
- builtin_
rounding_ op - Macro for rounding operations.
- builtin_
unary_ int - Macro for unary integer operations.
- builtin_
unary_ num - Macro for unary numeric operations (supports both int and float).
- builtin_
unary_ pred - Macro for unary predicate builtins.
- extract_
args - Macro to extract arguments from a Lisp list using car/cdr.
- register_
native - Register a native Rust function as a Lisp builtin with automatic argument extraction.
Structs§
- Arena
- Fixed-size arena allocator with O(1) allocation.
- Arena
Index - Index into the arena.
- ArgCount
Info - Compact argument count info (expected, got) packed into u32. Uses u16 for each count, supporting up to 65535 arguments.
- Display
Port - Write a
Valuethrough anIoProviderport. - Display
Value - A wrapper that enables
core::fmt::Displayfor Lisp values. - EnvRef
- A typed wrapper around
ArenaIndexrepresenting an environment chain. - Eval
Error - Evaluation error with context - optimized for minimal size.
- Evaluator
- The Lisp evaluator with full trampolined TCO.
- ExprRef
- A typed wrapper around
ArenaIndexrepresenting an expression to evaluate. - GcStats
- Statistics returned by garbage collection.
- Lisp
- A Lisp execution context wrapping an arena
- Null
IoProvider - A no-op I/O provider that silently discards all output and returns
IoErrorKind::Unsupportedfor reads. - Parse
Error - Parser error with location
- PortId
- Identifies an I/O port.
- Source
Loc - Source location for error reporting
- Stack
Frame - A stack frame for error reporting
Enums§
- Arena
Error - Errors that can occur during arena operations.
- Builtin
- Built-in functions (optimization to avoid symbol lookup)
- Cont
Type - Continuation types for the arena-based trampoline.
- Error
Kind - Error kind enumeration
- IoError
Kind - Error kinds for I/O operations in
no_stdenvironments. - Parse
Error Kind - StdLib
- Standard library functions (stored in static memory, not arena)
- Trampoline
State - Trampoline state - what we’re currently doing
- Value
- A Lisp value
Traits§
- GcRoots
- Trait for types that contain GC roots.
- IoProvider
- Trait for providing I/O operations to the evaluator.
- Trace
- Trait for types that can be traced by the garbage collector.
Functions§
- parse
- Parse a string into a Lisp expression
Type Aliases§
- Arena
Result - Result type for arena operations.
- Eval
Result - Result type for evaluation
- IoResult
- Result type for I/O operations.
- Output
Callback - Function pointer type for output callbacks
- fsize
- Platform-dependent floating-point type, matching the width of
isize/usize.