added new_with_vars
This commit is contained in:
parent
0134448472
commit
ca4a9aba4c
|
@ -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))?,
|
||||
}),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue