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