diff --git a/src/ast.rs b/src/ast.rs index b15cfe68..0cd0cfaf 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -151,6 +151,7 @@ impl AST { &mut self.0 } /// Get the internal shared [`Module`] containing all script-defined functions. + #[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_function"))] #[inline(always)] pub(crate) fn shared_lib(&self) -> Shared { diff --git a/src/fn_native.rs b/src/fn_native.rs index bb34c017..b86063eb 100644 --- a/src/fn_native.rs +++ b/src/fn_native.rs @@ -37,11 +37,11 @@ pub type Shared = Rc; pub type Shared = Arc; /// Synchronized shared object. -#[cfg(any(not(feature = "no_closure"), not(feature = "no_module")))] +#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "sync"))] pub type Locked = crate::stdlib::cell::RefCell; /// Synchronized shared object. -#[cfg(any(not(feature = "no_closure"), not(feature = "no_module")))] +#[cfg(not(feature = "no_closure"))] #[cfg(feature = "sync")] pub type Locked = crate::stdlib::sync::RwLock; diff --git a/src/lib.rs b/src/lib.rs index 601f9d5f..4e492c30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,7 +118,7 @@ pub type FLOAT = f32; pub use ast::{FnAccess, AST}; pub use dynamic::Dynamic; pub use engine::{Engine, EvalContext}; -pub use fn_native::{FnPtr, NativeCallContext}; +pub use fn_native::{FnPtr, NativeCallContext, Shared}; pub use fn_register::{RegisterFn, RegisterResultFn}; pub use module::{FnNamespace, Module}; pub use parse_error::{LexError, ParseError, ParseErrorType}; @@ -128,8 +128,8 @@ pub use syntax::Expression; pub use token::Position; pub use utils::ImmutableString; -#[allow(dead_code)] -use fn_native::{Locked, Shared}; +#[cfg(not(feature = "no_closure"))] +use fn_native::Locked; #[cfg(feature = "internals")] pub use utils::{calc_native_fn_hash, calc_script_fn_hash}; @@ -185,7 +185,11 @@ pub use ast::{ #[cfg(feature = "internals")] #[deprecated(note = "this type is volatile and may change")] -pub use engine::{Imports, Limits, State as EvalState}; +pub use engine::{Imports, State as EvalState}; + +#[cfg(feature = "internals")] +#[cfg(not(feature = "unchecked"))] +pub use engine::Limits; #[cfg(feature = "internals")] #[deprecated(note = "this type is volatile and may change")] diff --git a/src/module/mod.rs b/src/module/mod.rs index 725bb9fa..482dea48 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -9,7 +9,7 @@ use crate::stdlib::{ boxed::Box, collections::HashMap, fmt, format, - iter::{empty, once}, + iter::empty, num::NonZeroUsize, ops::{Add, AddAssign, Deref, DerefMut}, string::{String, ToString}, @@ -363,6 +363,8 @@ impl Module { // None + function name + number of arguments. let num_params = fn_def.params.len(); let hash_script = crate::calc_script_fn_hash(empty(), &fn_def.name, num_params); + let mut param_names: StaticVec<_> = fn_def.params.iter().cloned().collect(); + param_names.push("Dynamic".into()); self.functions.insert( hash_script, FuncInfo { @@ -371,14 +373,7 @@ impl Module { access: fn_def.access, params: num_params, param_types: None, - param_names: Some( - fn_def - .params - .iter() - .cloned() - .chain(once("Dynamic".into())) - .collect(), - ), + param_names: Some(param_names), func: fn_def.into(), }, ); diff --git a/src/module/resolvers/file.rs b/src/module/resolvers/file.rs index c8146b3c..3c509e96 100644 --- a/src/module/resolvers/file.rs +++ b/src/module/resolvers/file.rs @@ -1,7 +1,7 @@ use crate::stdlib::{ boxed::Box, collections::HashMap, io::Error as IoError, path::PathBuf, string::String, }; -use crate::{Engine, EvalAltResult, Locked, Module, ModuleResolver, Position, Shared}; +use crate::{Engine, EvalAltResult, Module, ModuleResolver, Position, Shared}; /// Module resolution service that loads module script files from the file system. /// @@ -37,7 +37,11 @@ use crate::{Engine, EvalAltResult, Locked, Module, ModuleResolver, Position, Sha pub struct FileModuleResolver { path: PathBuf, extension: String, - cache: Locked>>, + + #[cfg(not(feature = "sync"))] + cache: crate::stdlib::cell::RefCell>>, + #[cfg(feature = "sync")] + cache: crate::stdlib::sync::RwLock>>, } impl Default for FileModuleResolver { diff --git a/src/packages/fn_basic.rs b/src/packages/fn_basic.rs index ca153a97..e4592c33 100644 --- a/src/packages/fn_basic.rs +++ b/src/packages/fn_basic.rs @@ -1,6 +1,5 @@ use crate::plugin::*; -use crate::stdlib::iter::empty; -use crate::{calc_script_fn_hash, def_package, FnPtr, ImmutableString, NativeCallContext, INT}; +use crate::{def_package, FnPtr, ImmutableString, NativeCallContext}; #[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_index"))] @@ -20,6 +19,8 @@ mod fn_ptr_functions { #[cfg(not(feature = "no_function"))] pub mod functions { + use crate::{calc_script_fn_hash, stdlib::iter::empty, INT}; + #[rhai_fn(name = "is_anonymous", get = "is_anonymous")] pub fn is_anonymous(f: &mut FnPtr) -> bool { f.is_anonymous() diff --git a/src/parser.rs b/src/parser.rs index 57acdb08..6be6ca03 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -25,13 +25,16 @@ use crate::syntax::CustomSyntax; use crate::token::{is_keyword_function, is_valid_identifier, Token, TokenStream}; use crate::utils::{get_hasher, StraightHasherBuilder}; use crate::{ - calc_script_fn_hash, Dynamic, Engine, FnAccess, ImmutableString, LexError, ParseError, - ParseErrorType, Position, Scope, StaticVec, AST, + calc_script_fn_hash, Dynamic, Engine, ImmutableString, LexError, ParseError, ParseErrorType, + Position, Scope, StaticVec, AST, }; #[cfg(not(feature = "no_float"))] use crate::FLOAT; +#[cfg(not(feature = "no_function"))] +use crate::FnAccess; + type PERR = ParseErrorType; type FunctionsLib = HashMap;