Lines
100 %
Functions
Branches
//! Boxing an i32-repr value for a `$pair` car or an anyref slot. An index boxes
//! through the range-checked `box_index` into an i31. A bool boxes through
//! `box_bool` into `ref.null` (nil) / the `$t` singleton (t) — the SAME
//! representation whether the cell is typed `Bool` or `AnyRef` (ADR-0033), so
//! a bool car never needs rebuilding when its chain widens.
use crate::ast::{PairElement, WasmType};
use crate::compiler::context::CompileContext;
use crate::compiler::emit::FunctionEmitter;
/// Boxes a value of type `ty` (on the stack) into an anyref slot. References are
/// anyref subtypes already.
pub(in crate::compiler) fn emit_box_anyref(
ctx: &CompileContext,
emit: &mut FunctionEmitter,
ty: WasmType,
) {
match ty {
WasmType::I32 => emit.call(ctx.ids.box_index),
WasmType::Bool => emit.call(ctx.ids.box_bool),
_ => {}
}
/// Boxes a car of element `value` (on the stack) for a chain whose cells are
/// `slot`.
pub(in crate::compiler) fn emit_box_cell(
value: PairElement,
slot: PairElement,
match (slot, value) {
(PairElement::AnyRef, _) => emit_box_anyref(ctx, emit, value.as_wasm_type()),
(_, PairElement::I32) => emit.call(ctx.ids.box_index),
(_, PairElement::Bool) => emit.call(ctx.ids.box_bool),
#[cfg(test)]
#[path = "boxing_tests.rs"]
mod tests;