Lines
85.71 %
Functions
20 %
Branches
100 %
//! `COVERAGE-DUMP` — snapshot of per-native-fn compile-time
//! reference counts populated by the compiler's host-fn emit path.
//! Returns a string with one `name count` line per referenced native,
//! sorted alphabetically so test runners can diff the output for
//! stable assertions. Empty output means no native fn calls were
//! emitted in the session (typical for the language sandbox).
use crate::ast::{Expr, WasmType};
use crate::compiler::context::CompileContext;
use crate::compiler::emit::FunctionEmitter;
use crate::compiler::expr::compile_expr;
use crate::error::{Error, Result};
use crate::runtime::SymbolTable;
use super::compile_static_result_for_stack;
pub(super) fn coverage_dump(symbols: &mut SymbolTable, args: &[Expr]) -> Result<Expr> {
if !args.is_empty() {
return Err(Error::Arity {
name: "COVERAGE-DUMP".to_string(),
expected: 0,
actual: args.len(),
});
}
let mut entries: Vec<(&String, &u32)> = symbols.native_coverage().iter().collect();
entries.sort_by(|a, b| a.0.cmp(b.0));
let body = entries
.into_iter()
.map(|(name, count)| format!("{name} {count}"))
.collect::<Vec<_>>()
.join("\n");
Ok(Expr::String(body))
pub(super) fn compile_coverage_dump(
ctx: &mut CompileContext,
emit: &mut FunctionEmitter,
symbols: &mut SymbolTable,
args: &[Expr],
) -> Result<()> {
let result = coverage_dump(symbols, args)?;
compile_expr(ctx, emit, symbols, &result)
pub(super) fn compile_coverage_dump_for_stack(
) -> Result<WasmType> {
compile_static_result_for_stack(ctx, emit, symbols, &result)