pub struct Repl<'a> { /* private fields */ }Expand description
A REPL.
Implementations§
Source§impl<'a> Repl<'a>
impl<'a> Repl<'a>
Sourcepub fn empty(registry: &'a Registry, cfg: VmConfig) -> Result<Self, VmError>
pub fn empty(registry: &'a Registry, cfg: VmConfig) -> Result<Self, VmError>
Starts with an empty environment without a script.
Sourcepub fn from_program(
program: &'a Program,
registry: &'a Registry,
cfg: VmConfig,
) -> Result<Self, VmError>
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.
Sourcepub fn attach(vm: &Vm<'a>) -> Result<Self, VmError>
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.
Sourcepub fn submit(&mut self, input: &str) -> Result<Submitted, Vec<Diagnostic>>
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.
Sourcepub fn run(&mut self) -> Result<ReplYield, VmError>
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).
Sourcepub fn resume(&mut self, input: Input) -> Result<(), VmError>
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.
Sourcepub fn abort(&mut self)
pub fn abort(&mut self)
Discards input that is running (including stopped). The Repl returns to the state before the input.
Sourcepub fn package_state<P: Package>(&self) -> Option<&P::State>
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.
Sourcepub fn type_of(&self, input: &str) -> Result<Ty, Vec<Diagnostic>>
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.
Sourcepub fn variables(&self) -> Vec<Variable>
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>").
Sourcepub fn defs(&self) -> Vec<Def>
pub fn defs(&self) -> Vec<Def>
The fns, types, imports and identitys declared in the REPL (in declaration order).
Sourcepub fn interrupt_handle(&self) -> InterruptHandle
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.
Sourcepub fn reset(&mut self) -> Result<(), VmError>
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).
Sourcepub fn apply(&mut self, vm: &mut Vm<'a>) -> Result<Applied, ApplyError>
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.