Skip to main content

Repl

Struct Repl 

Source
pub struct Repl<'a> { /* private fields */ }
Expand description

A REPL.

Implementations§

Source§

impl<'a> Repl<'a>

Source

pub fn empty(registry: &'a Registry, cfg: VmConfig) -> Result<Self, VmError>

Starts with an empty environment without a script.

Source

pub fn from_program( program: &'a Program, registry: &'a Registry, cfg: VmConfig, ) -> Result<Self, VmError>

Starts on a copy of the state at the start of the script’s start label (before running). The start label may be missing.

Source

pub fn attach(vm: &Vm<'a>) -> Result<Self, VmError>

Starts on a copy of a stopped VM. vm is not changed (until apply is called). Err if it is not stopped.

Source

pub fn submit(&mut self, input: &str) -> Result<Submitted, Vec<Diagnostic>>

Type-checks input and prepares to run it (does not run it).

If the previous input has not finished (before Done, a runtime error or abort), returns Err without diagnostics. When diagnostics are returned, the state of the Repl is unchanged.

Source

pub fn run(&mut self) -> Result<ReplYield, VmError>

Runs the prepared input until the next stop point (or the end).

On a runtime error, the input is discarded (the Repl returns to the state before the input, and submit can be called again).

Source

pub fn resume(&mut self, input: Input) -> Result<(), VmError>

Resumes stopped input with the return value of the stop command.

Misuse such as a return value of the wrong type returns Err and stays stopped. On a runtime error, the input is discarded.

Source

pub fn abort(&mut self)

Discards input that is running (including stopped). The Repl returns to the state before the input.

Source

pub fn package_state<P: Package>(&self) -> Option<&P::State>

Reads the state slice of package P (read only). While input is running, reads that input’s state; otherwise, the state of the committed copy. Used by the host after run to read and show cues for sound and images. None if P is not registered.

Source

pub fn type_of(&self, input: &str) -> Result<Ty, Vec<Diagnostic>>

Finds the type of an expression (does not evaluate it). Err if it is not an expression.

Source

pub fn variables(&self) -> Vec<Variable>

The list of variables of the copy: script module variables, host-declared variables, local variables of the stop point (local is true), and REPL let variables, in that order. REPL let variables have module Some("<repl>").

Source

pub fn defs(&self) -> Vec<Def>

The fns, types, imports and identitys declared in the REPL (in declaration order).

Source

pub fn interrupt_handle(&self) -> InterruptHandle

The token that interrupts a running input from another thread (spec/host/01-execution.md, 1.9a). An interrupted input is discarded like any other runtime error.

Source

pub fn reset(&mut self) -> Result<(), VmError>

Discards the REPL declarations and returns the copy to the state when started (or, after apply, at that time).

Source

pub fn apply(&mut self, vm: &mut Vm<'a>) -> Result<Applied, ApplyError>

Applies the variables changed in the copy to the attached vm (section 7.3.6 of spec/host/07-repl.md). Either all are applied or none.

Only save vars, Kind::Save variables and local variables of the stop point whose values differ are applied. persistent vars are not applied and are listed in Applied::skipped. A Repl made with from_program or empty, and one whose input is running, gives NotAttached.

Trait Implementations§

Source§

impl<'a> Debug for Repl<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Repl<'a>

§

impl<'a> !UnwindSafe for Repl<'a>

§

impl<'a> Forget for Repl<'a>

§

impl<'a> Freeze for Repl<'a>

§

impl<'a> Move for Repl<'a>

§

impl<'a> Send for Repl<'a>

§

impl<'a> Sync for Repl<'a>

§

impl<'a> Unpin for Repl<'a>

§

impl<'a> UnsafeUnpin for Repl<'a>

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.