forked from AbleScript/ablescript
Host Interface initial vars support
This commit is contained in:
parent
2690c65c21
commit
61fbd3ee28
|
@ -1,5 +1,11 @@
|
||||||
|
use crate::value::Variable;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
/// Host Environment Interface
|
/// Host Environment Interface
|
||||||
pub trait HostInterface {
|
pub trait HostInterface {
|
||||||
|
/// Initial variables for a stack frame
|
||||||
|
fn initial_vars() -> 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<()>;
|
||||||
|
|
||||||
|
@ -17,6 +23,10 @@ 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> {
|
||||||
|
HashMap::default()
|
||||||
|
}
|
||||||
|
|
||||||
fn print(&mut self, string: &str, new_line: bool) -> std::io::Result<()> {
|
fn print(&mut self, string: &str, new_line: bool) -> std::io::Result<()> {
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,12 @@ impl<H: HostInterface> ExecEnv<H> {
|
||||||
/// other information.
|
/// other information.
|
||||||
pub fn with_host_interface(host_interface: H) -> Self {
|
pub fn with_host_interface(host_interface: H) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stack: vec![Default::default()],
|
stack: vec![
|
||||||
|
Default::default(),
|
||||||
|
Scope {
|
||||||
|
variables: H::initial_vars(),
|
||||||
|
},
|
||||||
|
],
|
||||||
read_buf: Default::default(),
|
read_buf: Default::default(),
|
||||||
finalisers: vec![],
|
finalisers: vec![],
|
||||||
host_interface,
|
host_interface,
|
||||||
|
@ -103,12 +108,15 @@ impl<H: HostInterface> ExecEnv<H> {
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = (String, Variable)>,
|
I: IntoIterator<Item = (String, Variable)>,
|
||||||
{
|
{
|
||||||
let scope = Scope {
|
|
||||||
variables: ablescript_consts().into_iter().chain(vars).collect(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
stack: vec![scope],
|
stack: vec![
|
||||||
|
Scope {
|
||||||
|
variables: ablescript_consts().into_iter().chain(vars).collect(),
|
||||||
|
},
|
||||||
|
Scope {
|
||||||
|
variables: H::initial_vars(),
|
||||||
|
},
|
||||||
|
],
|
||||||
read_buf: Default::default(),
|
read_buf: Default::default(),
|
||||||
finalisers: vec![],
|
finalisers: vec![],
|
||||||
host_interface,
|
host_interface,
|
||||||
|
|
Loading…
Reference in a new issue