diff --git a/src/ast.rs b/src/ast.rs index 9be4301b..87aeaeb5 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -2,7 +2,7 @@ use crate::dynamic::{AccessMode, Union}; use crate::fn_native::shared_make_mut; -use crate::module::{resolvers::StaticModuleResolver, NamespaceRef}; +use crate::module::NamespaceRef; use crate::stdlib::{ borrow::Cow, boxed::Box, @@ -171,7 +171,8 @@ pub struct AST { /// Script-defined functions. functions: Shared, /// Embedded module resolver, if any. - resolver: Option>, + #[cfg(not(feature = "no_module"))] + resolver: Option>, } impl Default for AST { @@ -181,6 +182,7 @@ impl Default for AST { source: None, statements: Vec::with_capacity(16), functions: Default::default(), + #[cfg(not(feature = "no_module"))] resolver: None, } } @@ -197,6 +199,7 @@ impl AST { source: None, statements: statements.into_iter().collect(), functions: functions.into(), + #[cfg(not(feature = "no_module"))] resolver: None, } } @@ -211,6 +214,7 @@ impl AST { source: Some(source.into()), statements: statements.into_iter().collect(), functions: functions.into(), + #[cfg(not(feature = "no_module"))] resolver: None, } } @@ -275,23 +279,27 @@ impl AST { &self.functions } /// Get the embedded [module resolver][`ModuleResolver`]. - #[cfg(not(feature = "internals"))] + #[cfg(not(feature = "no_module"))] #[inline(always)] - pub(crate) fn shared_resolver(&self) -> Option> { + pub(crate) fn shared_resolver( + &self, + ) -> Option> { self.resolver.clone() } /// _(INTERNALS)_ Get the embedded [module resolver][`ModuleResolver`]. /// Exported under the `internals` feature only. + #[cfg(not(feature = "no_module"))] #[cfg(feature = "internals")] #[inline(always)] pub fn resolver(&self) -> Option<&dyn crate::ModuleResolver> { self.resolver.map(|r| &*r) } /// Set the embedded [module resolver][`ModuleResolver`]. + #[cfg(not(feature = "no_module"))] #[inline(always)] pub(crate) fn set_resolver( &mut self, - resolver: impl Into>, + resolver: impl Into>, ) -> &mut Self { self.resolver = Some(resolver.into()); self @@ -325,6 +333,7 @@ impl AST { source: self.source.clone(), statements: Default::default(), functions: functions.into(), + #[cfg(not(feature = "no_module"))] resolver: self.resolver.clone(), } } @@ -336,6 +345,7 @@ impl AST { source: self.source.clone(), statements: self.statements.clone(), functions: Default::default(), + #[cfg(not(feature = "no_module"))] resolver: self.resolver.clone(), } } @@ -633,6 +643,7 @@ impl AST { /// /// Not available under [`no_function`]. #[cfg(not(feature = "no_function"))] + #[cfg(not(feature = "no_module"))] #[inline(always)] pub(crate) fn iter_fn_def(&self) -> impl Iterator { self.functions @@ -968,9 +979,9 @@ impl Stmt { x.0.walk(process_stmt, process_expr); x.2.walk(process_stmt, process_expr); } - Self::Expr(e) | Self::Return(_, Some(e), _) | Self::Import(e, _, _) => { - e.walk(process_stmt, process_expr) - } + Self::Expr(e) | Self::Return(_, Some(e), _) => e.walk(process_stmt, process_expr), + #[cfg(not(feature = "no_module"))] + Self::Import(e, _, _) => e.walk(process_stmt, process_expr), _ => (), } } diff --git a/src/engine.rs b/src/engine.rs index 6b220376..77f0b8aa 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -7,7 +7,7 @@ use crate::fn_native::{ CallableFunction, IteratorFn, OnDebugCallback, OnPrintCallback, OnProgressCallback, OnVarCallback, }; -use crate::module::{resolvers::StaticModuleResolver, NamespaceRef}; +use crate::module::NamespaceRef; use crate::optimize::OptimizationLevel; use crate::packages::{Package, StandardPackage}; use crate::r#unsafe::unsafe_cast_var_name_to_lifetime; @@ -26,8 +26,8 @@ use crate::stdlib::{ use crate::syntax::CustomSyntax; use crate::utils::{get_hasher, StraightHasherBuilder}; use crate::{ - calc_native_fn_hash, Dynamic, EvalAltResult, FnPtr, ImmutableString, Module, ModuleResolver, - Position, Scope, Shared, StaticVec, + calc_native_fn_hash, Dynamic, EvalAltResult, FnPtr, ImmutableString, Module, Position, Scope, + Shared, StaticVec, }; #[cfg(not(feature = "no_index"))] @@ -517,7 +517,8 @@ pub struct State { /// Number of modules loaded. pub modules: usize, /// Embedded module resolver. - pub resolver: Option>, + #[cfg(not(feature = "no_module"))] + pub resolver: Option>, /// Cached lookup values for function hashes. pub functions_cache: HashMap< NonZeroU64, @@ -2330,6 +2331,8 @@ impl Engine { .eval_expr(scope, mods, state, lib, this_ptr, &expr, level)? .try_cast::() { + use crate::ModuleResolver; + let expr_pos = expr.position(); let module = state diff --git a/src/engine_api.rs b/src/engine_api.rs index bb28b8c0..02775b00 100644 --- a/src/engine_api.rs +++ b/src/engine_api.rs @@ -896,8 +896,6 @@ impl Engine { /// via the current [module resolver][crate::ModuleResolver] and embedded into the resultant /// [`AST`]. When it is evaluated later, `import` statement directly recall pre-resolved /// [modules][Module] and the resolution process is not performed again. - /// - /// Not available under `no_module`. #[cfg(not(feature = "no_module"))] pub fn compile_into_self_contained( &self, @@ -917,7 +915,16 @@ impl Engine { ast.statements() .iter() - .chain(ast.iter_fn_def().map(|f| &f.body)) + .chain({ + #[cfg(not(feature = "no_function"))] + { + ast.iter_fn_def().map(|f| &f.body) + } + #[cfg(feature = "no_function")] + { + crate::stdlib::iter::empty() + } + }) .for_each(|stmt| { stmt.walk( &mut |stmt| match stmt { @@ -1512,6 +1519,7 @@ impl Engine { ) -> Result> { let state = &mut State { source: ast.clone_source(), + #[cfg(not(feature = "no_module"))] resolver: ast.shared_resolver(), ..Default::default() }; @@ -1580,6 +1588,7 @@ impl Engine { let mods = &mut (&self.global_sub_modules).into(); let state = &mut State { source: ast.clone_source(), + #[cfg(not(feature = "no_module"))] resolver: ast.shared_resolver(), ..Default::default() };