added new_with_vars

pull/5/head
ondra05 2022-02-14 00:08:48 +01:00
parent 23fcb800c4
commit 5f4c0da06a
1 changed files with 18 additions and 1 deletions

View File

@ -87,6 +87,21 @@ impl ExecEnv {
}
}
/// Create a new Scope with predefined variables
pub fn new_with_vars<I>(vars: I) -> Self
where
I: IntoIterator<Item = (String, Variable)>,
{
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))?,
}),
);