Lines
100 %
Functions
20 %
Branches
//! Reflective / introspection special forms — `COMPILE`, `EVAL`,
//! `DESCRIBE`, `PP`, `APROPOS`, `DEFTEST`, `ASSERT-EQUAL`,
//! `RUN-TESTS`, `COVERAGE-DUMP`.
//!
//! Split by feature so each submodule stays under the ~500-line
//! CLAUDE.md guideline:
//! - [`compile_eval_forms`] — COMPILE + EVAL (handlers in both
//! directions, plus their value-position counterparts).
//! - [`describe_pp`] — DESCRIBE + PP (both produce String summaries).
//! - [`apropos`] — symbol-table search returning a sorted quoted list.
//! - [`test_framework`] — DEFTEST + ASSERT-EQUAL + RUN-TESTS.
//! - [`coverage`] — COVERAGE-DUMP snapshot of native-fn references.
mod apropos;
mod compile_eval_forms;
mod coverage;
mod describe_pp;
mod test_framework;
#[cfg(test)]
mod tests;
use crate::ast::{Expr, WasmType};
use crate::compiler::context::CompileContext;
use crate::compiler::emit::FunctionEmitter;
use crate::compiler::expr::{compile_for_stack, format_expr};
use crate::error::Result;
use crate::runtime::SymbolTable;
use super::SpecialFormSpec;
/// Compiles a constant-folded Expr result onto the wasm stack. Forms
/// like PP / DESCRIBE / RUN-TESTS already return `Expr::String`, but
/// COMPILE / DEFTEST / APROPOS return `Expr::Quote(...)`. Both flavours
/// need to land on the stack as a single StringRef at value position;
/// Quote results get formatted to their textual form via `format_expr`
/// so the eval-mode client receives a presentable wire payload.
pub(in crate::compiler::special::compile_eval) fn compile_static_result_for_stack(
ctx: &mut CompileContext,
emit: &mut FunctionEmitter,
symbols: &mut SymbolTable,
result: &Expr,
) -> Result<WasmType> {
let staged = match result {
Expr::Quote(_) => Expr::String(format_expr(result)),
other => other.clone(),
};
compile_for_stack(ctx, emit, symbols, &staged)
}
pub(super) const FORMS: &[SpecialFormSpec] = &[
SpecialFormSpec {
name: "COMPILE",
eval: compile_eval_forms::compile_form,
compile: compile_eval_forms::compile_compile_form,
stack: Some(compile_eval_forms::compile_compile_form_for_stack),
effect: None,
},
name: "EVAL",
eval: compile_eval_forms::eval_form,
compile: compile_eval_forms::compile_eval_form,
stack: Some(compile_eval_forms::compile_eval_form_for_stack),
name: "DESCRIBE",
eval: describe_pp::describe,
compile: describe_pp::compile_describe,
stack: Some(describe_pp::compile_describe_for_stack),
name: "PP",
eval: describe_pp::pp,
compile: describe_pp::compile_pp,
stack: Some(describe_pp::compile_pp_for_stack),
name: "APROPOS",
eval: apropos::apropos,
compile: apropos::compile_apropos,
stack: Some(apropos::compile_apropos_for_stack),
name: "DEFTEST",
eval: test_framework::deftest,
compile: test_framework::compile_deftest,
stack: Some(test_framework::compile_deftest_for_stack),
name: "ASSERT-EQUAL",
eval: test_framework::assert_equal,
compile: test_framework::compile_assert_equal,
stack: Some(test_framework::compile_assert_equal_for_stack),
name: "RUN-TESTS",
eval: test_framework::run_tests,
compile: test_framework::compile_run_tests,
stack: Some(test_framework::compile_run_tests_for_stack),
name: "COVERAGE-DUMP",
eval: coverage::coverage_dump,
compile: coverage::compile_coverage_dump,
stack: Some(coverage::compile_coverage_dump_for_stack),
];