//! Captured program run (for tests and `view`). use crate::host::PlotArtifact; use crate::value::Value; /// Silent execution trace for view annotations (not stderr `trace_eval`). #[derive(Debug, Clone, Default)] pub struct ViewTrace { pub branches: Vec, pub loops: Vec, /// Per-statement post-state / control events (tree capture). pub events: Vec, /// User-function invocations (tree capture). pub calls: Vec, /// Foreach / while loop frames with per-iteration item values. pub loop_frames: Vec, } #[derive(Debug, Clone)] pub struct BranchHit { pub line: u32, pub arm_index: usize, pub count: u32, /// Call frame that took this arm (`0` = entry / `# main`). pub call_id: u32, } #[derive(Debug, Clone)] pub struct LoopHit { pub line: u32, pub iterations: u32, pub last_item: Option, } #[derive(Debug, Clone)] pub struct LoopFrame { pub loop_id: u32, pub line: u32, pub item_name: Option, pub collection: Option, pub iterations: Vec, } #[derive(Debug, Clone)] pub struct LoopIter { /// 0-based iteration index. pub index: u32, pub item_value: String, pub call_id: u32, } #[derive(Debug, Clone)] pub struct StmtEvent { pub line: u32, pub kind: StmtEventKind, pub name: Option, pub value_after: Option, pub arm_index: Option, /// 0-based iteration index when inside a loop. pub iter: Option, pub call_id: u32, pub loop_id: Option, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum StmtEventKind { Assign, Return, Call, Branch, Loop, BindRef, } impl StmtEventKind { pub fn as_str(self) -> &'static str { match self { StmtEventKind::Assign => "assign", StmtEventKind::Return => "return", StmtEventKind::Call => "call", StmtEventKind::Branch => "branch", StmtEventKind::Loop => "loop", StmtEventKind::BindRef => "bind_ref", } } } #[derive(Debug, Clone)] pub struct CallFrame { pub call_id: u32, pub fn_name: String, pub fn_line: u32, pub ordinal: u32, pub args_brief: String, } #[derive(Debug, Clone)] pub struct RunCapture { pub stdout: String, pub value: Value, pub plots: Vec, /// Entry-function bindings after a successful tree-backend run (empty for bytecode). pub bindings: std::collections::HashMap, /// Branch/loop/stmt hits collected during tree capture (empty for bytecode). pub view_trace: ViewTrace, }