forked from AbleScript/ablescript
initial vars - &mut self
This commit is contained in:
parent
e936585112
commit
4dfddc2cdb
|
@ -4,7 +4,7 @@ use std::collections::HashMap;
|
|||
/// Host Environment Interface
|
||||
pub trait HostInterface {
|
||||
/// Initial variables for a stack frame
|
||||
fn initial_vars() -> HashMap<String, Variable>;
|
||||
fn initial_vars(&mut self) -> HashMap<String, Variable>;
|
||||
|
||||
/// Print a string
|
||||
fn print(&mut self, string: &str, new_line: bool) -> std::io::Result<()>;
|
||||
|
@ -23,7 +23,7 @@ pub trait HostInterface {
|
|||
#[derive(Clone, Copy, Default)]
|
||||
pub struct Standard;
|
||||
impl HostInterface for Standard {
|
||||
fn initial_vars() -> HashMap<String, Variable> {
|
||||
fn initial_vars(&mut self) -> HashMap<String, Variable> {
|
||||
HashMap::default()
|
||||
}
|
||||
|
||||
|
|
|
@ -89,12 +89,12 @@ pub const READ_BITS: u8 = 3;
|
|||
impl<H: HostInterface> ExecEnv<H> {
|
||||
/// Create a new Scope with no predefined variable definitions or
|
||||
/// other information.
|
||||
pub fn with_host_interface(host_interface: H) -> Self {
|
||||
pub fn with_host_interface(mut host_interface: H) -> Self {
|
||||
Self {
|
||||
stack: vec![
|
||||
Default::default(),
|
||||
Scope {
|
||||
variables: H::initial_vars(),
|
||||
variables: host_interface.initial_vars(),
|
||||
},
|
||||
],
|
||||
read_buf: Default::default(),
|
||||
|
@ -104,7 +104,7 @@ impl<H: HostInterface> ExecEnv<H> {
|
|||
}
|
||||
|
||||
/// Create a new Scope with predefined variables
|
||||
pub fn new_with_vars<I>(host_interface: H, vars: I) -> Self
|
||||
pub fn new_with_vars<I>(mut host_interface: H, vars: I) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = (String, Variable)>,
|
||||
{
|
||||
|
@ -114,7 +114,7 @@ impl<H: HostInterface> ExecEnv<H> {
|
|||
variables: ablescript_consts().into_iter().chain(vars).collect(),
|
||||
},
|
||||
Scope {
|
||||
variables: H::initial_vars(),
|
||||
variables: host_interface.initial_vars(),
|
||||
},
|
||||
],
|
||||
read_buf: Default::default(),
|
||||
|
|
Loading…
Reference in a new issue