Make caches optional for EvalContext.

This commit is contained in:
Stephen Chung
2022-04-16 23:32:14 +08:00
parent 855cb76246
commit daf73d5341
10 changed files with 61 additions and 67 deletions

View File

@@ -7,24 +7,24 @@ use std::prelude::v1::*;
/// Context of a script evaluation process.
#[derive(Debug)]
pub struct EvalContext<'a, 'x, 'px, 'm, 'pm, 'c, 'b, 't, 'pt> {
pub struct EvalContext<'a, 's, 'ps, 'm, 'pm, 'c, 't, 'pt> {
/// The current [`Engine`].
pub(crate) engine: &'a Engine,
/// The current [`Scope`].
pub(crate) scope: &'x mut Scope<'px>,
pub(crate) scope: &'s mut Scope<'ps>,
/// The current [`GlobalRuntimeState`].
pub(crate) global: &'m mut GlobalRuntimeState<'pm>,
/// The current [caches][Caches].
pub(crate) caches: &'c mut Caches,
/// The current [caches][Caches], if available.
pub(crate) caches: Option<&'c mut Caches>,
/// The current stack of imported [modules][Module].
pub(crate) lib: &'b [&'b Module],
pub(crate) lib: &'a [&'a Module],
/// The current bound `this` pointer, if any.
pub(crate) this_ptr: &'t mut Option<&'pt mut Dynamic>,
/// The current nesting level of function calls.
pub(crate) level: usize,
}
impl<'x, 'px, 'm, 'pm, 'pt> EvalContext<'_, 'x, 'px, 'm, 'pm, '_, '_, '_, 'pt> {
impl<'s, 'ps, 'm, 'pm, 'pt> EvalContext<'_, 's, 'ps, 'm, 'pm, '_, '_, 'pt> {
/// The current [`Engine`].
#[inline(always)]
#[must_use]
@@ -44,13 +44,13 @@ impl<'x, 'px, 'm, 'pm, 'pt> EvalContext<'_, 'x, 'px, 'm, 'pm, '_, '_, '_, 'pt> {
/// The current [`Scope`].
#[inline(always)]
#[must_use]
pub const fn scope(&self) -> &Scope<'px> {
pub const fn scope(&self) -> &Scope<'ps> {
self.scope
}
/// Get a mutable reference to the current [`Scope`].
#[inline(always)]
#[must_use]
pub fn scope_mut(&mut self) -> &mut &'x mut Scope<'px> {
pub fn scope_mut(&mut self) -> &mut &'s mut Scope<'ps> {
&mut self.scope
}
/// Get an iterator over the current set of modules imported via `import` statements,