Fix sync build.
This commit is contained in:
parent
c93e94c7cd
commit
c397a6dcb5
@ -92,13 +92,13 @@ impl Engine {
|
||||
// global::VARIABLE
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
if namespace.len() == 1 && namespace[0].name == crate::engine::KEYWORD_GLOBAL {
|
||||
let mut guard = crate::func::native::locked_write(&global.constants);
|
||||
|
||||
if let Some(value) = guard.get_mut(var_name) {
|
||||
let mut target: Target = value.clone().into();
|
||||
// Module variables are constant
|
||||
target.set_access_mode(AccessMode::ReadOnly);
|
||||
return Ok((target.into(), *_var_pos));
|
||||
if let Some(ref constants) = global.constants {
|
||||
if let Some(value) = crate::func::locked_write(constants).get_mut(var_name) {
|
||||
let mut target: Target = value.clone().into();
|
||||
// Module variables are constant
|
||||
target.set_access_mode(AccessMode::ReadOnly);
|
||||
return Ok((target.into(), *_var_pos));
|
||||
}
|
||||
}
|
||||
|
||||
return Err(ERR::ErrorVariableNotFound(
|
||||
|
@ -42,9 +42,13 @@ pub struct GlobalRuntimeState<'a> {
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
pub embedded_module_resolver: Option<Shared<crate::module::resolvers::StaticModuleResolver>>,
|
||||
/// Cache of globally-defined constants.
|
||||
///
|
||||
/// 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: crate::Locked<std::collections::BTreeMap<Identifier, crate::Dynamic>>,
|
||||
pub(crate) constants: Option<
|
||||
crate::Shared<crate::Locked<std::collections::BTreeMap<Identifier, crate::Dynamic>>>,
|
||||
>,
|
||||
/// Debugging interface.
|
||||
#[cfg(feature = "debugging")]
|
||||
pub debugger: super::Debugger,
|
||||
@ -71,7 +75,7 @@ impl GlobalRuntimeState<'_> {
|
||||
fn_hash_indexing: (0, 0),
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
constants: std::collections::BTreeMap::new().into(),
|
||||
constants: None,
|
||||
#[cfg(feature = "debugging")]
|
||||
debugger: crate::eval::Debugger::new(_engine),
|
||||
dummy: PhantomData::default(),
|
||||
|
@ -818,7 +818,12 @@ impl Engine {
|
||||
&& entry_type == AccessMode::ReadOnly
|
||||
&& lib.iter().any(|&m| !m.is_empty())
|
||||
{
|
||||
crate::func::native::locked_write(&global.constants)
|
||||
if global.constants.is_none() {
|
||||
global.constants = Some(crate::Shared::new(crate::Locked::new(
|
||||
std::collections::BTreeMap::new(),
|
||||
)));
|
||||
}
|
||||
crate::func::locked_write(global.constants.as_ref().unwrap())
|
||||
.insert(var_name.clone(), value.clone());
|
||||
}
|
||||
|
||||
|
@ -1685,7 +1685,6 @@ impl Module {
|
||||
// Save global state
|
||||
let orig_imports_len = global.num_imports();
|
||||
let orig_source = global.source.clone();
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
let orig_constants = std::mem::take(&mut global.constants);
|
||||
|
||||
@ -1719,7 +1718,6 @@ impl Module {
|
||||
}
|
||||
|
||||
// Restore global state
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
{
|
||||
global.constants = orig_constants;
|
||||
|
Loading…
Reference in New Issue
Block a user