Lines
93.33 %
Functions
20 %
Branches
100 %
//! `BEGIN` special form. Sequencing primitive — evaluates each body
//! form in order, returning the last value. Empty body collapses to
//! `nil`.
use crate::ast::{Expr, WasmType};
use crate::compiler::context::CompileContext;
use crate::compiler::emit::FunctionEmitter;
use crate::compiler::expr::{compile_body, compile_body_for_stack, compile_nil};
use crate::error::Result;
use crate::runtime::SymbolTable;
pub(super) fn compile_begin(
ctx: &mut CompileContext,
emit: &mut FunctionEmitter,
symbols: &mut SymbolTable,
args: &[Expr],
) -> Result<()> {
if args.is_empty() {
compile_nil(ctx, emit);
return Ok(());
}
compile_body(ctx, emit, symbols, args)
pub(super) fn compile_begin_for_stack(
) -> Result<WasmType> {
// Empty `(begin)` ≡ nil; push the falsy i31 value but type it `Bool`
// so it serializes as Nil (not Number(0)) and agrees with the eval
// mirror (`begin_form` → `Expr::Nil`), keeping a runtime-IF branch
// homogeneous.
emit.i32_const(0);
return Ok(WasmType::Bool);
compile_body_for_stack(ctx, emit, symbols, args)
pub(super) fn begin_form(symbols: &mut SymbolTable, args: &[Expr]) -> Result<Expr> {
return Ok(Expr::Nil);
super::super::binding::eval_body(symbols, args)