Lines
42.59 %
Functions
5.71 %
Branches
100 %
use super::super::context::CompileContext;
use super::super::emit::FunctionEmitter;
use super::super::expr::{compile_nil, eval_value, format_expr};
use crate::ast::Expr;
use crate::error::Result;
use crate::runtime::SymbolTable;
const SCRATCH_OFFSET: u32 = 0;
pub(super) fn debug_call(symbols: &mut SymbolTable, args: &[Expr]) -> Result<Expr> {
let parts: Vec<String> = args
.iter()
.map(|a| eval_value(symbols, a).map(|r| format_expr(&r)))
.collect::<Result<_>>()?;
let msg = parts.join(" ");
tracing::debug!("[script] {msg}");
Ok(Expr::Nil)
}
pub(in crate::compiler) fn compile_debug_effect(
ctx: &mut CompileContext,
emit: &mut FunctionEmitter,
symbols: &mut SymbolTable,
args: &[Expr],
) -> Result<()> {
let resolved: std::result::Result<Vec<_>, _> =
args.iter().map(|a| eval_value(symbols, a)).collect();
let msg = resolved?
.map(format_expr)
.collect::<Vec<_>>()
.join(" ");
let data_idx = ctx.add_data(msg.as_bytes());
let len = msg.len() as u32;
emit.memory_init(data_idx, SCRATCH_OFFSET, len);
emit.i32_const(0);
emit.i32_const(SCRATCH_OFFSET as i32);
emit.i32_const(len as i32);
emit.call(ctx.func("log"));
Ok(())
pub(super) fn compile_debug(
emit.i32_const(0); // level = debug
compile_nil(ctx, emit);