Skip to main content

Vm

Struct Vm 

Source
pub struct Vm { /* private fields */ }
Expand description

The Harn bytecode virtual machine.

Implementations§

Source§

impl Vm

Source

pub fn format_runtime_error(&self, error: &VmError) -> String

Source§

impl Vm

Source

pub fn new() -> Self

Source

pub fn set_bridge(&mut self, bridge: Rc<HostBridge>)

Set the bridge for delegating unknown builtins in bridge mode.

Source

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.

Source

pub fn set_source_info(&mut self, file: &str, text: &str)

Set source info for error reporting (file path and source text).

Source

pub fn set_breakpoints(&mut self, lines: Vec<usize>)

Set breakpoints by source line number.

Source

pub fn set_step_mode(&mut self, step: bool)

Enable step mode (stop at next line).

Source

pub fn set_step_over(&mut self)

Enable step-over mode (stop at next line at same or lower frame depth).

Source

pub fn set_step_out(&mut self)

Enable step-out mode (stop when returning from current frame).

Source

pub fn is_stopped(&self) -> bool

Check if the VM is stopped at a debug point.

Source

pub fn debug_state(&self) -> DebugState

Get the current debug state (variables, line, etc.).

Source

pub fn debug_stack_frames(&self) -> Vec<(String, usize)>

Get all stack frames for the debugger.

Source

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.

Source

pub fn start(&mut self, chunk: &Chunk)

Initialize execution (push the initial frame).

Source

pub fn register_builtin<F>(&mut self, name: &str, f: F)
where F: Fn(&[VmValue], &mut String) -> Result<VmValue, VmError> + 'static,

Register a sync builtin function.

Source

pub fn unregister_builtin(&mut self, name: &str)

Remove a sync builtin (so an async version can take precedence).

Source

pub fn register_async_builtin<F, Fut>(&mut self, name: &str, f: F)
where F: Fn(Vec<VmValue>) -> Fut + 'static, Fut: Future<Output = Result<VmValue, VmError>> + 'static,

Register an async builtin function.

Source

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.

Source

pub fn set_project_root(&mut self, root: &Path)

Explicitly set the project root directory. Used by ACP/CLI to override auto-detection.

Source

pub fn project_root(&self) -> Option<&Path>

Get the project root directory, falling back to source_dir.

Source

pub fn builtin_names(&self) -> Vec<String>

Return all registered builtin names (sync + async).

Source

pub fn set_global(&mut self, name: &str, value: VmValue)

Set a global variable in the VM’s environment.

Source

pub fn output(&self) -> &str

Get the captured output.

Source

pub async fn execute(&mut self, chunk: &Chunk) -> Result<VmValue, VmError>

Execute a compiled chunk.

Trait Implementations§

Source§

impl Default for Vm

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more