Skip to main content

shape_vm/executor/vm_impl/
output.rs

1use super::super::*;
2
3impl VirtualMachine {
4    /// Enable output capture for testing
5    /// When enabled, print output goes to an internal buffer instead of stdout
6    pub fn enable_output_capture(&mut self) {
7        self.output_buffer = Some(Vec::new());
8    }
9
10    /// Disable output capture — print goes to stdout again.
11    pub fn disable_output_capture(&mut self) {
12        self.output_buffer = None;
13    }
14
15    /// Get captured output (returns empty vec if capture not enabled)
16    pub fn get_captured_output(&self) -> Vec<String> {
17        self.output_buffer.clone().unwrap_or_default()
18    }
19
20    /// Clear captured output
21    pub fn clear_captured_output(&mut self) {
22        if let Some(ref mut buf) = self.output_buffer {
23            buf.clear();
24        }
25    }
26
27    /// Write to output (either buffer or stdout)
28    pub(crate) fn write_output(&mut self, text: &str) {
29        if let Some(ref mut buf) = self.output_buffer {
30            buf.push(text.to_string());
31        } else {
32            println!("{}", text);
33        }
34    }
35
36    /// Set a module_binding variable by name.
37    ///
38    /// Phase-1b-vm: the storage-tier parallel-kind track for module
39    /// bindings has landed (`module_binding_kinds` companion vec, ADR-
40    /// 006 §2.7.8 / Q10) and `module_binding_write_kinded` is the
41    /// kinded implementation backbone for any future host-API mutator.
42    /// The signature is now kinded per ADR-006 §2.7 / Q7 — the
43    /// `KindedSlot` carrier is the boundary shape.
44    pub(crate) fn set_module_binding_by_name_nb(&mut self, _name: &str, _value: KindedSlot) {
45        todo!(
46            "phase-2c — see ADR-006 §2.7.4: set_module_binding_by_name_nb \
47             dispatch through `module_binding_write_kinded` (§2.7.8 \
48             parallel track is live); host-API caller wiring lands in \
49             the Phase-2c host rebuild"
50        );
51    }
52
53    /// Get the line number of the last error (for LSP integration)
54    pub fn last_error_line(&self) -> Option<u32> {
55        self.last_error_line
56    }
57
58    /// Get the file path of the last error (for LSP integration)
59    pub fn last_error_file(&self) -> Option<&str> {
60        self.last_error_file.as_deref()
61    }
62
63    /// Capture an uncaught exception payload for host-side rendering.
64    ///
65    /// Per ADR-006 §2.7 / Q7 the boundary carrier is `KindedSlot`.
66    pub(crate) fn set_last_uncaught_exception(&mut self, value: KindedSlot) {
67        self.last_uncaught_exception = Some(value);
68    }
69
70    /// Clear any previously captured uncaught exception payload.
71    pub(crate) fn clear_last_uncaught_exception(&mut self) {
72        self.last_uncaught_exception = None;
73    }
74
75    /// Take the last uncaught exception payload if present.
76    pub fn take_last_uncaught_exception(&mut self) -> Option<KindedSlot> {
77        self.last_uncaught_exception.take()
78    }
79}