Lines
83.33 %
Functions
10 %
Branches
100 %
//! `DELETE-ENTITY` codegen. Takes an entity index, reads the
//! `entity_type` byte at the entity's header offset, and routes
//! through the layout serializer to emit a delete-record entry in the
//! output stream.
use crate::ast::{Expr, WasmType};
use crate::compiler::context::CompileContext;
use crate::compiler::emit::FunctionEmitter;
use crate::compiler::expr::LOCAL_TEMP_I32;
use crate::error::Result;
use crate::runtime::SymbolTable;
use super::{arity_check, compile_idx_to_stack, emit_entity_header_offset};
pub(super) fn delete_entity(_symbols: &mut SymbolTable, args: &[Expr]) -> Result<Expr> {
arity_check("DELETE-ENTITY", args, 1)?;
Ok(Expr::Nil)
}
pub(super) fn compile_delete_entity(
ctx: &mut CompileContext,
emit: &mut FunctionEmitter,
symbols: &mut SymbolTable,
args: &[Expr],
) -> Result<()> {
compile_idx_to_stack(ctx, emit, symbols, &args[0])?;
let temp = LOCAL_TEMP_I32;
emit_entity_header_offset(ctx, emit, temp)?;
let header_local = ctx.alloc_local(WasmType::I32)?;
emit.local_set(header_local);
// Read entity_type from input header
let type_local = ctx.alloc_local(WasmType::I32)?;
emit.local_get(header_local);
emit.i32_load8_u(0);
emit.local_set(type_local);
ctx.serializer()
.write_delete_entity(emit, type_local, header_local);
Ok(())