Skip to main content

myriad/
debug.rs

1use alloc::{boxed::Box, string::String};
2use polka::{OpCode, Value};
3
4pub enum DebugEvent<'a> {
5    Trace {
6        func: usize,
7        pc: usize,
8        op: &'a OpCode,
9        base_reg: usize,
10        // The current fn's register window and which of those regs hold handles.
11        window: &'a [u64],
12        handle_mask: u128,
13        // Source line of this op (0 = no debug info).
14        line: u32,
15        // Source file of this fn ("" = unknown).
16        file: &'a str,
17    },
18    HandlePush {
19        effect_id: u16,
20        cell_slot: u32,
21        cell_gen: u32,
22        suspend_pc: usize,
23        suspend_base: usize,
24        dest: usize,
25        depth: usize,
26    },
27    Resume {
28        saved_pc: usize,
29        saved_base: usize,
30        cell_dest: usize,
31        val: Value,
32        handler_dest: usize,
33        alive: Value,
34        depth: usize,
35    },
36}
37
38pub type DebugSink = Box<dyn FnMut(&DebugEvent, &[String])>;
39
40/// Symbolic label for a function id: "name#id" if a non-empty name is known,
41/// "#id" otherwise. Used by trace, halt errors, anywhere a fn is rendered.
42pub fn render_fn_label(idx: usize, names: &[String]) -> String {
43    match names.get(idx) {
44        Some(n) if !n.is_empty() => format!("{}#{}", n, idx),
45        _ => format!("#{}", idx),
46    }
47}