diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index a2239e27..ba9191f6 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -87,6 +87,21 @@ impl ExecEnv { } } + /// Create a new Scope with predefined variables + pub fn new_with_vars(vars: I) -> Self + where + I: IntoIterator, + { + let scope = Scope { + variables: ablescript_consts().into_iter().chain(vars).collect(), + }; + + Self { + stack: vec![scope], + read_buf: Default::default(), + } + } + /// Execute a set of Statements in the root stack frame. Return an /// error if one or more of the Stmts failed to evaluate, or if a /// `break` or `hopback` statement occurred at the top level. @@ -224,7 +239,9 @@ impl ExecEnv { instructions: code.to_owned(), tape_len: tape_len .as_ref() - .map(|tape_len| self.eval_expr(tape_len).map(|v| v.into_isize() as usize)) + .map(|tape_len| { + self.eval_expr(tape_len).map(|v| v.into_isize() as usize) + }) .unwrap_or(Ok(crate::brian::DEFAULT_TAPE_SIZE_LIMIT))?, }), );