Fix encapsulated environment in module functions.

This commit is contained in:
Stephen Chung
2022-01-30 17:27:13 +08:00
parent 8fc80ecd10
commit 7b92a80c32
13 changed files with 150 additions and 63 deletions

View File

@@ -5,6 +5,12 @@ use crate::{Engine, Identifier};
use std::prelude::v1::*;
use std::{fmt, marker::PhantomData};
/// Collection of globally-defined constants.
#[cfg(not(feature = "no_module"))]
#[cfg(not(feature = "no_function"))]
pub type GlobalConstants =
crate::Shared<crate::Locked<std::collections::BTreeMap<Identifier, crate::Dynamic>>>;
/// _(internals)_ Global runtime states.
/// Exported under the `internals` feature only.
//
@@ -44,9 +50,7 @@ pub struct GlobalRuntimeState<'a> {
/// Interior mutability is needed because it is shared in order to aid in cloning.
#[cfg(not(feature = "no_module"))]
#[cfg(not(feature = "no_function"))]
pub(crate) constants: Option<
crate::Shared<crate::Locked<std::collections::BTreeMap<Identifier, crate::Dynamic>>>,
>,
pub(crate) constants: Option<GlobalConstants>,
/// Debugging interface.
#[cfg(feature = "debugging")]
pub debugger: super::Debugger,

View File

@@ -17,5 +17,8 @@ pub use debugger::CallStackFrame;
pub use debugger::{BreakPoint, Debugger, DebuggerCommand, OnDebuggerCallback, OnDebuggingInit};
pub use eval_context::EvalContext;
pub use eval_state::EvalState;
#[cfg(not(feature = "no_module"))]
#[cfg(not(feature = "no_function"))]
pub use global_state::GlobalConstants;
pub use global_state::GlobalRuntimeState;
pub use target::{calc_index, calc_offset_len, Target};