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