pub struct Vm { /* private fields */ }Expand description
The Harn bytecode virtual machine.
Implementations§
Source§impl Vm
impl Vm
pub fn new() -> Self
Sourcepub fn set_bridge(&mut self, bridge: Rc<HostBridge>)
pub fn set_bridge(&mut self, bridge: Rc<HostBridge>)
Set the bridge for delegating unknown builtins in bridge mode.
Sourcepub fn set_denied_builtins(&mut self, denied: HashSet<String>)
pub fn set_denied_builtins(&mut self, denied: HashSet<String>)
Set builtins that are denied in sandbox mode. When called, the given builtin names will produce a permission error.
Sourcepub fn set_source_info(&mut self, file: &str, text: &str)
pub fn set_source_info(&mut self, file: &str, text: &str)
Set source info for error reporting (file path and source text).
Sourcepub fn set_breakpoints_for_file(&mut self, file: &str, lines: Vec<usize>)
pub fn set_breakpoints_for_file(&mut self, file: &str, lines: Vec<usize>)
Replace breakpoints for a single source file. Pass an empty string
(or call set_breakpoints for the wildcard equivalent) to install
breakpoints that match every file — useful for ad-hoc CLI runs
where the embedder doesn’t track per-file source paths.
Sourcepub fn set_breakpoints(&mut self, lines: Vec<usize>)
pub fn set_breakpoints(&mut self, lines: Vec<usize>)
Backwards-compatible wildcard form. Stores all lines under the empty-string key, which matches any source file at the check site. Existing embedders that don’t track file scoping still work.
Sourcepub fn set_step_mode(&mut self, step: bool)
pub fn set_step_mode(&mut self, step: bool)
Enable step mode (stop at next line).
Sourcepub fn set_step_over(&mut self)
pub fn set_step_over(&mut self)
Enable step-over mode (stop at next line at same or lower frame depth).
Sourcepub fn set_debug_hook<F>(&mut self, hook: F)
pub fn set_debug_hook<F>(&mut self, hook: F)
Register a debug hook invoked whenever execution advances to a new source line.
Sourcepub fn clear_debug_hook(&mut self)
pub fn clear_debug_hook(&mut self)
Clear the current debug hook.
Sourcepub fn set_step_out(&mut self)
pub fn set_step_out(&mut self)
Enable step-out mode (stop when returning from current frame).
Sourcepub fn is_stopped(&self) -> bool
pub fn is_stopped(&self) -> bool
Check if the VM is stopped at a debug point.
Sourcepub fn debug_state(&self) -> DebugState
pub fn debug_state(&self) -> DebugState
Get the current debug state (variables, line, etc.).
Sourcepub fn debug_stack_frames(&self) -> Vec<(String, usize)>
pub fn debug_stack_frames(&self) -> Vec<(String, usize)>
Get all stack frames for the debugger.
Sourcepub async fn step_execute(&mut self) -> Result<Option<(VmValue, bool)>, VmError>
pub async fn step_execute(&mut self) -> Result<Option<(VmValue, bool)>, VmError>
Execute one instruction, returning whether to stop (breakpoint/step). Returns Ok(None) to continue, Ok(Some(val)) on program end, Err on error.
Sourcepub fn register_builtin<F>(&mut self, name: &str, f: F)
pub fn register_builtin<F>(&mut self, name: &str, f: F)
Register a sync builtin function.
Sourcepub fn unregister_builtin(&mut self, name: &str)
pub fn unregister_builtin(&mut self, name: &str)
Remove a sync builtin (so an async version can take precedence).
Sourcepub fn register_async_builtin<F, Fut>(&mut self, name: &str, f: F)
pub fn register_async_builtin<F, Fut>(&mut self, name: &str, f: F)
Register an async builtin function.
Sourcepub fn set_source_dir(&mut self, dir: &Path)
pub fn set_source_dir(&mut self, dir: &Path)
Set the source directory for import resolution and introspection. Also auto-detects the project root if not already set.
Sourcepub fn set_project_root(&mut self, root: &Path)
pub fn set_project_root(&mut self, root: &Path)
Explicitly set the project root directory. Used by ACP/CLI to override auto-detection.
Sourcepub fn project_root(&self) -> Option<&Path>
pub fn project_root(&self) -> Option<&Path>
Get the project root directory, falling back to source_dir.
Sourcepub fn builtin_names(&self) -> Vec<String>
pub fn builtin_names(&self) -> Vec<String>
Return all registered builtin names (sync + async).
Sourcepub fn set_global(&mut self, name: &str, value: VmValue)
pub fn set_global(&mut self, name: &str, value: VmValue)
Set a global constant (e.g. pi, e).
Stored separately from the environment so user-defined variables can shadow them.
Sourcepub async fn execute(&mut self, chunk: &Chunk) -> Result<VmValue, VmError>
pub async fn execute(&mut self, chunk: &Chunk) -> Result<VmValue, VmError>
Execute a compiled chunk.
Sourcepub async fn call_closure_pub(
&mut self,
closure: &VmClosure,
args: &[VmValue],
functions: &[CompiledFunction],
) -> Result<VmValue, VmError>
pub async fn call_closure_pub( &mut self, closure: &VmClosure, args: &[VmValue], functions: &[CompiledFunction], ) -> Result<VmValue, VmError>
Public wrapper for call_closure, used by the MCP server to invoke
tool handler closures from outside the VM execution loop.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Vm
impl !RefUnwindSafe for Vm
impl !Send for Vm
impl !Sync for Vm
impl Unpin for Vm
impl UnsafeUnpin for Vm
impl !UnwindSafe for Vm
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);