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_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.
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.
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 fn format_runtime_error(&self, error: &VmError) -> String
pub fn format_runtime_error(&self, error: &VmError) -> String
Format a runtime error with stack trace and source context.
Produces rustc-style output with source context and caret highlighting:
error: Undefined variable: x
--> file.harn:5:12
|
5 | let y = x + 1
| ^
= note: called from greet at file.harn:2:1