Lines
100 %
Functions
Branches
//! The v1 closure-value shape gate: only required-only lambdas become wasm
//! closure values; every other lambda value is the one structured error.
use crate::ast::{Expr, LambdaParams};
use crate::error::{Error, Result};
use crate::runtime::SymbolTable;
/// Whether `params` / `body` fit the v1 emit slice: required-only params;
/// captures of stable locals are supported.
pub(super) fn is_v1_eligible(_symbols: &SymbolTable, params: &LambdaParams, _body: &Expr) -> bool {
has_v1_param_shape(params)
}
pub(in crate::compiler) fn non_v1_lambda_error() -> Error {
Error::Compile(
"lambda value with &optional/&rest/&key/&aux not yet supported as a \
first-class wasm closure; rewrite the lambda to take only required \
parameters or invoke it inline (the const-fold path still handles \
keyword args)"
.to_string(),
)
pub(in crate::compiler) fn reject_non_v1_lambda(expr: &Expr) -> Result<()> {
match expr {
Expr::Lambda(params, _) if !has_v1_param_shape(params) => Err(non_v1_lambda_error()),
_ => Ok(()),
pub(in crate::compiler) fn has_v1_param_shape(params: &LambdaParams) -> bool {
params.optional.is_empty()
&& params.rest.is_none()
&& params.key.is_empty()
&& params.aux.is_empty()
#[cfg(test)]
#[path = "shape_tests.rs"]
mod tests;