Lines
100 %
Functions
33.33 %
Branches
//! Boxing an i32-repr value for a `$pair` car or an anyref slot. An index boxes
//! through the range-checked `box_index`; a bool is i31 0/1 in a bool-typed
//! cell, but `nil`-as-null in an anyref slot, where `null?` tests
//! `ref.is_null`.
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.ref_i31(),
/// Retypes a `from` chain (on the stack) as a `to` chain. Only a bool chain's
/// cells (i31 0 nils) differ from their anyref form, so it alone is rebuilt;
/// every other cell is already a valid anyref car.
pub(in crate::compiler) fn emit_relabel_chain(
from: PairElement,
to: PairElement,
if from == PairElement::Bool && to == PairElement::AnyRef {
emit.call(ctx.ids.bool_chain_to_anyref);