diff --git a/src/api/call_fn.rs b/src/api/call_fn.rs index 06d8af04..335be57d 100644 --- a/src/api/call_fn.rs +++ b/src/api/call_fn.rs @@ -253,9 +253,7 @@ impl Engine { let orig_lib_len = global.lib.len(); #[cfg(not(feature = "no_function"))] - if ast.has_functions() { - global.lib.push(ast.functions().clone()); - } + global.lib.push(ast.shared_lib().clone()); let mut no_this_ptr = Dynamic::NULL; let this_ptr = this_ptr.unwrap_or(&mut no_this_ptr); diff --git a/src/api/eval.rs b/src/api/eval.rs index 6e2601e4..2c5ffb70 100644 --- a/src/api/eval.rs +++ b/src/api/eval.rs @@ -212,9 +212,7 @@ impl Engine { let orig_lib_len = global.lib.len(); #[cfg(not(feature = "no_function"))] - if ast.has_functions() { - global.lib.push(ast.functions().clone()); - } + global.lib.push(ast.shared_lib().clone()); #[cfg(not(feature = "no_module"))] let orig_embedded_module_resolver = mem::replace( diff --git a/src/api/run.rs b/src/api/run.rs index 3c4d823a..a83a3a73 100644 --- a/src/api/run.rs +++ b/src/api/run.rs @@ -116,9 +116,8 @@ impl Engine { global.source = ast.source_raw().cloned(); #[cfg(not(feature = "no_function"))] - if ast.has_functions() { - global.lib.push(ast.functions().clone()); - } + global.lib.push(ast.shared_lib().clone()); + #[cfg(not(feature = "no_module"))] { global.embedded_module_resolver = ast.resolver().cloned(); diff --git a/src/ast/ast.rs b/src/ast/ast.rs index 26226f6e..71b07669 100644 --- a/src/ast/ast.rs +++ b/src/ast/ast.rs @@ -57,12 +57,11 @@ impl fmt::Debug for AST { fp.field("body", &self.body.as_slice()); #[cfg(not(feature = "no_function"))] - if !self.lib.is_empty() { - for (.., fn_def) in self.lib.iter_script_fn() { - let sig = fn_def.to_string(); - fp.field(&sig, &fn_def.body.as_slice()); - } + for (.., fn_def) in self.lib.iter_script_fn() { + let sig = fn_def.to_string(); + fp.field(&sig, &fn_def.body.as_slice()); } + fp.finish() } } @@ -231,23 +230,6 @@ impl AST { pub(crate) fn set_doc(&mut self, doc: impl Into) { self.doc = doc.into(); } - /// Get the shared [module][crate::Module] containing script-defined functions. - #[cfg(not(feature = "no_function"))] - #[cfg(not(feature = "internals"))] - #[inline(always)] - #[must_use] - pub(crate) fn functions(&self) -> &crate::SharedModule { - &self.lib - } - /// _(internals)_ Get the shared [module][crate::Module] containing script-defined functions. - /// Exported under the `internals` feature only. - #[cfg(not(feature = "no_function"))] - #[cfg(feature = "internals")] - #[inline(always)] - #[must_use] - pub fn functions(&self) -> &crate::SharedModule { - &self.lib - } /// Get the statements. #[cfg(not(feature = "internals"))] #[inline(always)] @@ -756,7 +738,7 @@ impl AST { &mut self, filter: impl Fn(FnNamespace, FnAccess, &str, usize) -> bool, ) -> &mut Self { - if !self.lib.is_empty() { + if self.has_functions() { crate::func::shared_make_mut(&mut self.lib).retain_script_functions(filter); } self diff --git a/src/func/call.rs b/src/func/call.rs index dff6e528..4dcc7ced 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -1445,7 +1445,7 @@ impl Engine { // If new functions are defined within the eval string, it is an error #[cfg(not(feature = "no_function"))] - if !ast.shared_lib().is_empty() { + if ast.has_functions() { return Err(crate::PERR::WrongFnDefinition.into()); } diff --git a/src/func/script.rs b/src/func/script.rs index cc733691..55ba1361 100644 --- a/src/func/script.rs +++ b/src/func/script.rs @@ -118,9 +118,7 @@ impl Engine { .cloned() .for_each(|(n, m)| global.push_import(n, m)); - if !lib.is_empty() { - global.lib.push(lib.clone()); - } + global.lib.push(lib.clone()); Some(mem::replace(&mut global.constants, constants.clone())) } else { diff --git a/src/module/mod.rs b/src/module/mod.rs index e468cfa0..91be1a53 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -543,14 +543,13 @@ impl Module { #[inline] #[must_use] pub fn is_empty(&self) -> bool { - self.indexed - && !self.contains_indexed_global_functions + !self.contains_indexed_global_functions && self.functions.is_empty() - && self.all_functions.as_ref().map_or(true, |m| m.is_empty()) && self.variables.as_ref().map_or(true, |m| m.is_empty()) - && self.all_variables.as_ref().map_or(true, |m| m.is_empty()) && self.modules.as_ref().map_or(true, |m| m.is_empty()) && self.type_iterators.as_ref().map_or(true, |t| t.is_empty()) + && self.all_functions.as_ref().map_or(true, |m| m.is_empty()) + && self.all_variables.as_ref().map_or(true, |m| m.is_empty()) && self .all_type_iterators .as_ref() diff --git a/src/types/fn_ptr.rs b/src/types/fn_ptr.rs index c193749e..900b738b 100644 --- a/src/types/fn_ptr.rs +++ b/src/types/fn_ptr.rs @@ -154,9 +154,7 @@ impl FnPtr { let global = &mut GlobalRuntimeState::new(engine); #[cfg(not(feature = "no_function"))] - if _ast.has_functions() { - global.lib.push(_ast.functions().clone()); - } + global.lib.push(_ast.shared_lib().clone()); let ctx = (engine, self.fn_name(), None, &*global, Position::NONE).into();