Fix builds

This commit is contained in:
Stephen Chung 2020-11-27 23:37:59 +08:00
parent a0979d0c35
commit 36546c7325
7 changed files with 29 additions and 21 deletions

View File

@ -151,6 +151,7 @@ impl AST {
&mut self.0 &mut self.0
} }
/// Get the internal shared [`Module`] containing all script-defined functions. /// Get the internal shared [`Module`] containing all script-defined functions.
#[cfg(not(feature = "no_module"))]
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
#[inline(always)] #[inline(always)]
pub(crate) fn shared_lib(&self) -> Shared<Module> { pub(crate) fn shared_lib(&self) -> Shared<Module> {

View File

@ -37,11 +37,11 @@ pub type Shared<T> = Rc<T>;
pub type Shared<T> = Arc<T>; pub type Shared<T> = Arc<T>;
/// Synchronized shared object. /// Synchronized shared object.
#[cfg(any(not(feature = "no_closure"), not(feature = "no_module")))] #[cfg(not(feature = "no_closure"))]
#[cfg(not(feature = "sync"))] #[cfg(not(feature = "sync"))]
pub type Locked<T> = crate::stdlib::cell::RefCell<T>; pub type Locked<T> = crate::stdlib::cell::RefCell<T>;
/// Synchronized shared object. /// Synchronized shared object.
#[cfg(any(not(feature = "no_closure"), not(feature = "no_module")))] #[cfg(not(feature = "no_closure"))]
#[cfg(feature = "sync")] #[cfg(feature = "sync")]
pub type Locked<T> = crate::stdlib::sync::RwLock<T>; pub type Locked<T> = crate::stdlib::sync::RwLock<T>;

View File

@ -118,7 +118,7 @@ pub type FLOAT = f32;
pub use ast::{FnAccess, AST}; pub use ast::{FnAccess, AST};
pub use dynamic::Dynamic; pub use dynamic::Dynamic;
pub use engine::{Engine, EvalContext}; 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 fn_register::{RegisterFn, RegisterResultFn};
pub use module::{FnNamespace, Module}; pub use module::{FnNamespace, Module};
pub use parse_error::{LexError, ParseError, ParseErrorType}; pub use parse_error::{LexError, ParseError, ParseErrorType};
@ -128,8 +128,8 @@ pub use syntax::Expression;
pub use token::Position; pub use token::Position;
pub use utils::ImmutableString; pub use utils::ImmutableString;
#[allow(dead_code)] #[cfg(not(feature = "no_closure"))]
use fn_native::{Locked, Shared}; use fn_native::Locked;
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
pub use utils::{calc_native_fn_hash, calc_script_fn_hash}; pub use utils::{calc_native_fn_hash, calc_script_fn_hash};
@ -185,7 +185,11 @@ pub use ast::{
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
#[deprecated(note = "this type is volatile and may change")] #[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")] #[cfg(feature = "internals")]
#[deprecated(note = "this type is volatile and may change")] #[deprecated(note = "this type is volatile and may change")]

View File

@ -9,7 +9,7 @@ use crate::stdlib::{
boxed::Box, boxed::Box,
collections::HashMap, collections::HashMap,
fmt, format, fmt, format,
iter::{empty, once}, iter::empty,
num::NonZeroUsize, num::NonZeroUsize,
ops::{Add, AddAssign, Deref, DerefMut}, ops::{Add, AddAssign, Deref, DerefMut},
string::{String, ToString}, string::{String, ToString},
@ -363,6 +363,8 @@ impl Module {
// None + function name + number of arguments. // None + function name + number of arguments.
let num_params = fn_def.params.len(); let num_params = fn_def.params.len();
let hash_script = crate::calc_script_fn_hash(empty(), &fn_def.name, num_params); 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( self.functions.insert(
hash_script, hash_script,
FuncInfo { FuncInfo {
@ -371,14 +373,7 @@ impl Module {
access: fn_def.access, access: fn_def.access,
params: num_params, params: num_params,
param_types: None, param_types: None,
param_names: Some( param_names: Some(param_names),
fn_def
.params
.iter()
.cloned()
.chain(once("Dynamic".into()))
.collect(),
),
func: fn_def.into(), func: fn_def.into(),
}, },
); );

View File

@ -1,7 +1,7 @@
use crate::stdlib::{ use crate::stdlib::{
boxed::Box, collections::HashMap, io::Error as IoError, path::PathBuf, string::String, 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. /// 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 { pub struct FileModuleResolver {
path: PathBuf, path: PathBuf,
extension: String, extension: String,
cache: Locked<HashMap<PathBuf, Shared<Module>>>,
#[cfg(not(feature = "sync"))]
cache: crate::stdlib::cell::RefCell<HashMap<PathBuf, Shared<Module>>>,
#[cfg(feature = "sync")]
cache: crate::stdlib::sync::RwLock<HashMap<PathBuf, Shared<Module>>>,
} }
impl Default for FileModuleResolver { impl Default for FileModuleResolver {

View File

@ -1,6 +1,5 @@
use crate::plugin::*; use crate::plugin::*;
use crate::stdlib::iter::empty; use crate::{def_package, FnPtr, ImmutableString, NativeCallContext};
use crate::{calc_script_fn_hash, def_package, FnPtr, ImmutableString, NativeCallContext, INT};
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
@ -20,6 +19,8 @@ mod fn_ptr_functions {
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
pub mod functions { pub mod functions {
use crate::{calc_script_fn_hash, stdlib::iter::empty, INT};
#[rhai_fn(name = "is_anonymous", get = "is_anonymous")] #[rhai_fn(name = "is_anonymous", get = "is_anonymous")]
pub fn is_anonymous(f: &mut FnPtr) -> bool { pub fn is_anonymous(f: &mut FnPtr) -> bool {
f.is_anonymous() f.is_anonymous()

View File

@ -25,13 +25,16 @@ use crate::syntax::CustomSyntax;
use crate::token::{is_keyword_function, is_valid_identifier, Token, TokenStream}; use crate::token::{is_keyword_function, is_valid_identifier, Token, TokenStream};
use crate::utils::{get_hasher, StraightHasherBuilder}; use crate::utils::{get_hasher, StraightHasherBuilder};
use crate::{ use crate::{
calc_script_fn_hash, Dynamic, Engine, FnAccess, ImmutableString, LexError, ParseError, calc_script_fn_hash, Dynamic, Engine, ImmutableString, LexError, ParseError, ParseErrorType,
ParseErrorType, Position, Scope, StaticVec, AST, Position, Scope, StaticVec, AST,
}; };
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
use crate::FLOAT; use crate::FLOAT;
#[cfg(not(feature = "no_function"))]
use crate::FnAccess;
type PERR = ParseErrorType; type PERR = ParseErrorType;
type FunctionsLib = HashMap<u64, ScriptFnDef, StraightHasherBuilder>; type FunctionsLib = HashMap<u64, ScriptFnDef, StraightHasherBuilder>;