Fix feature builds.
This commit is contained in:
parent
9f71e5b155
commit
bfe9ac2188
27
src/ast.rs
27
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<Module>,
|
||||
/// Embedded module resolver, if any.
|
||||
resolver: Option<Shared<StaticModuleResolver>>,
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
resolver: Option<Shared<crate::module::resolvers::StaticModuleResolver>>,
|
||||
}
|
||||
|
||||
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<Shared<StaticModuleResolver>> {
|
||||
pub(crate) fn shared_resolver(
|
||||
&self,
|
||||
) -> Option<Shared<crate::module::resolvers::StaticModuleResolver>> {
|
||||
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<Shared<StaticModuleResolver>>,
|
||||
resolver: impl Into<Shared<crate::module::resolvers::StaticModuleResolver>>,
|
||||
) -> &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<Item = &ScriptFnDef> {
|
||||
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),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
@ -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<Shared<StaticModuleResolver>>,
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
pub resolver: Option<Shared<crate::module::resolvers::StaticModuleResolver>>,
|
||||
/// 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::<ImmutableString>()
|
||||
{
|
||||
use crate::ModuleResolver;
|
||||
|
||||
let expr_pos = expr.position();
|
||||
|
||||
let module = state
|
||||
|
@ -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<Dynamic, Box<EvalAltResult>> {
|
||||
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()
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user