Struct endbasic_core::exec::Machine
source · [−]pub struct Machine { /* private fields */ }
Expand description
Executes an EndBASIC program and tracks its state.
Implementations
sourceimpl Machine
impl Machine
sourcepub fn add_clearable(&mut self, clearable: Box<dyn Clearable>)
pub fn add_clearable(&mut self, clearable: Box<dyn Clearable>)
Registers the given clearable.
In the common case, functions and commands hold a reference to the out-of-machine state
they interact with. This state is invisible from here, but we may need to have access
to it to reset it as part of the clear
operation. In those cases, such state must be
registered via this hook.
sourcepub fn add_command(&mut self, command: Rc<dyn Command>)
pub fn add_command(&mut self, command: Rc<dyn Command>)
Registers the given builtin command, which must not yet be registered.
sourcepub fn add_function(&mut self, function: Rc<dyn Function>)
pub fn add_function(&mut self, function: Rc<dyn Function>)
Registers the given builtin function, which must not yet be registered.
sourcepub fn exit(&mut self, code: u8)
pub fn exit(&mut self, code: u8)
Tells the machine to stop execution at the next statement boundary.
The exec()
call that’s stopped by this invocation will return the code
given to this
call.
sourcepub fn get_symbols(&self) -> &Symbols
pub fn get_symbols(&self) -> &Symbols
Obtains immutable access to the state of the symbols.
sourcepub fn get_mut_symbols(&mut self) -> &mut Symbols
pub fn get_mut_symbols(&mut self) -> &mut Symbols
Obtains mutable access to the state of the symbols.
sourcepub fn get_var_as_bool(&self, name: &str) -> Result<bool>
pub fn get_var_as_bool(&self, name: &str) -> Result<bool>
Retrieves the variable name
as a boolean. Fails if it is some other type or if it’s not
defined.
sourcepub fn get_var_as_int(&self, name: &str) -> Result<i32>
pub fn get_var_as_int(&self, name: &str) -> Result<i32>
Retrieves the variable name
as an integer. Fails if it is some other type or if it’s not
defined.
sourcepub fn get_var_as_string(&self, name: &str) -> Result<&str>
pub fn get_var_as_string(&self, name: &str) -> Result<&str>
Retrieves the variable name
as a string. Fails if it is some other type or if it’s not
defined.
sourcepub async fn dim_array(
&mut self,
name: &str,
subtype: &VarType,
dimensions: &[Expr]
) -> Result<()>
pub async fn dim_array(
&mut self,
name: &str,
subtype: &VarType,
dimensions: &[Expr]
) -> Result<()>
Defines a new array name
of type subtype
with dimensions
. The array must not yet
exist, and the name may not overlap function or variable names.
sourcepub async fn exec(&mut self, input: &mut dyn Read) -> Result<StopReason>
pub async fn exec(&mut self, input: &mut dyn Read) -> Result<StopReason>
Executes a program extracted from the input
readable.
Note that this does not consume self
. As a result, it is possible to execute multiple
different programs on the same machine, all sharing state.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Machine
impl !Send for Machine
impl !Sync for Machine
impl Unpin for Machine
impl !UnwindSafe for Machine
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more