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(&mut self, lines: Vec<usize>)
pub fn set_breakpoints(&mut self, lines: Vec<usize>)
Set breakpoints by source line number.
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_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 variable in the VM’s environment. Globals are defined before user code runs, so collisions are not possible.
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.