Lines
100 %
Functions
91.67 %
Branches
//! `QUOTE` special form. Evaluation returns `Expr::Datum(datum)`, the same
//! value the reader's `'x` evaluates to, so both spellings are one value on the eval
//! surface (P8's reader half is cut, ISS-040); compilation routes through
//! `Expr::quoted` and `compile_expr` so list literals materialize via the proper
//! cons-cell allocator instead of being re-evaluated. In effect position a
//! quote form is a no-op.
use crate::ast::{Expr, WasmType};
use crate::compiler::context::CompileContext;
use crate::compiler::emit::FunctionEmitter;
use crate::compiler::expr::{compile_expr, compile_for_stack};
use crate::error::{Error, Result};
use crate::runtime::SymbolTable;
pub(super) fn eval_quote(_symbols: &mut SymbolTable, args: &[Expr]) -> Result<Expr> {
Ok(Expr::quoted(quote(args)?))
}
pub(super) fn compile_quote_effect(
_ctx: &mut CompileContext,
_emit: &mut FunctionEmitter,
_symbols: &mut SymbolTable,
args: &[Expr],
) -> Result<()> {
quote(args).map(drop)
pub(super) fn spec_compile_quote(
ctx: &mut CompileContext,
emit: &mut FunctionEmitter,
symbols: &mut SymbolTable,
compile_quote(ctx, emit, symbols, args)
pub(super) fn compile_quote(
compile_expr(ctx, emit, symbols, &Expr::quoted(quote(args)?))
pub(super) fn compile_quote_for_stack(
) -> Result<WasmType> {
let datum = quote(args)?;
compile_for_stack(ctx, emit, symbols, &Expr::quoted(datum))
pub(super) fn quote(args: &[Expr]) -> Result<Expr> {
if args.len() != 1 {
return Err(Error::Arity {
name: "quote".to_string(),
expected: 1,
actual: args.len(),
});
Ok(args[0].clone())
#[cfg(test)]
#[path = "quote_tests.rs"]
mod tests;