diff --git a/ablescript/src/host_interface.rs b/ablescript/src/host_interface.rs index d8db0236..e0920e2d 100644 --- a/ablescript/src/host_interface.rs +++ b/ablescript/src/host_interface.rs @@ -1,5 +1,11 @@ +use crate::value::Variable; +use std::collections::HashMap; + /// Host Environment Interface pub trait HostInterface { + /// Initial variables for a stack frame + fn initial_vars() -> HashMap; + /// Print a string fn print(&mut self, string: &str, new_line: bool) -> std::io::Result<()>; @@ -17,6 +23,10 @@ pub trait HostInterface { #[derive(Clone, Copy, Default)] pub struct Standard; impl HostInterface for Standard { + fn initial_vars() -> HashMap { + HashMap::default() + } + fn print(&mut self, string: &str, new_line: bool) -> std::io::Result<()> { use std::io::Write; diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index d74a32ff..6274e517 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -91,7 +91,12 @@ impl ExecEnv { /// other information. pub fn with_host_interface(host_interface: H) -> Self { Self { - stack: vec![Default::default()], + stack: vec![ + Default::default(), + Scope { + variables: H::initial_vars(), + }, + ], read_buf: Default::default(), finalisers: vec![], host_interface, @@ -103,12 +108,15 @@ impl ExecEnv { where I: IntoIterator, { - let scope = Scope { - variables: ablescript_consts().into_iter().chain(vars).collect(), - }; - Self { - stack: vec![scope], + stack: vec![ + Scope { + variables: ablescript_consts().into_iter().chain(vars).collect(), + }, + Scope { + variables: H::initial_vars(), + }, + ], read_buf: Default::default(), finalisers: vec![], host_interface,