From adc96e24bd4239177f2e565c460bca9ad62aec30 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 13 Jul 2020 19:38:50 +0800 Subject: [PATCH] Fix all features. --- RELEASES.md | 3 ++- src/any.rs | 6 ++++-- src/engine.rs | 13 ++++++++++++- src/fn_native.rs | 4 ++-- src/fn_register.rs | 7 ++++++- src/module.rs | 4 +++- src/packages/mod.rs | 2 +- src/settings.rs | 2 ++ src/stdlib.rs | 2 +- src/syntax.rs | 2 +- src/token.rs | 2 +- tests/call_fn.rs | 1 + tests/tokens.rs | 1 + 13 files changed, 37 insertions(+), 12 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 541b8177..9cde45dd 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -7,10 +7,10 @@ Version 0.17.0 This version adds: * [`serde`](https://crates.io/crates/serde) support for working with `Dynamic` values (particularly _object maps_). +* Low-level API to register functions. * Surgically disable keywords and/or operators in the language. * Define custom operators. * Extend the language via custom syntax. -* Low-level API to register functions. Bug fixes --------- @@ -41,6 +41,7 @@ New features * Many configuration/setting API's now returns `&mut Self` so that the calls can be chained. * `String` parameters in functions are supported (but inefficiently). + Version 0.16.1 ============== diff --git a/src/any.rs b/src/any.rs index bd21404b..5182da08 100644 --- a/src/any.rs +++ b/src/any.rs @@ -212,9 +212,11 @@ pub(crate) fn map_std_type_name(name: &str) -> &str { "string" } else if name == type_name::() { "Fn" - } else if name == type_name::() { - "timestamp" } else { + #[cfg(not(feature = "no_std"))] + if name == type_name::() { + return "timestamp"; + } #[cfg(not(feature = "no_index"))] if name == type_name::() { return "array"; diff --git a/src/engine.rs b/src/engine.rs index 1c39120f..69eaf371 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -26,7 +26,7 @@ use crate::stdlib::{ boxed::Box, collections::{HashMap, HashSet}, convert::TryFrom, - format, + fmt, format, iter::{empty, once}, mem, string::{String, ToString}, @@ -96,6 +96,7 @@ pub const MARKER_BLOCK: &str = "$block$"; pub const MARKER_IDENT: &str = "$ident$"; #[cfg(feature = "internals")] +#[derive(Debug, Clone)] pub struct Expression<'a>(&'a Expr); #[cfg(feature = "internals")] @@ -346,6 +347,15 @@ pub struct Engine { pub(crate) max_map_size: usize, } +impl fmt::Debug for Engine { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.id.as_ref() { + Some(id) => write!(f, "Engine({})", id), + None => f.write_str("Engine"), + } + } +} + impl Default for Engine { fn default() -> Self { // Create the new scripting Engine @@ -1095,6 +1105,7 @@ impl Engine { let mut hash = *hash; // Check if it is a map method call in OOP style + #[cfg(not(feature = "no_object"))] if let Some(map) = obj.downcast_ref::() { if let Some(val) = map.get(fn_name) { if let Some(f) = val.downcast_ref::() { diff --git a/src/fn_native.rs b/src/fn_native.rs index 399d1746..dabcbe21 100644 --- a/src/fn_native.rs +++ b/src/fn_native.rs @@ -7,7 +7,7 @@ use crate::result::EvalAltResult; use crate::token::{is_valid_identifier, Position}; use crate::utils::ImmutableString; -use crate::stdlib::{boxed::Box, convert::TryFrom, fmt, rc::Rc, sync::Arc}; +use crate::stdlib::{boxed::Box, convert::TryFrom, fmt, rc::Rc, string::String, sync::Arc}; /// Trait that maps to `Send + Sync` only under the `sync` feature. #[cfg(feature = "sync")] @@ -86,7 +86,7 @@ impl TryFrom for FnPtr { Ok(Self(value)) } else { Err(Box::new(EvalAltResult::ErrorFunctionNotFound( - value.to_string(), + value.into(), Position::none(), ))) } diff --git a/src/fn_register.rs b/src/fn_register.rs index 23d8043f..4192140a 100644 --- a/src/fn_register.rs +++ b/src/fn_register.rs @@ -10,7 +10,12 @@ use crate::r#unsafe::unsafe_cast_box; use crate::result::EvalAltResult; use crate::utils::ImmutableString; -use crate::stdlib::{any::TypeId, boxed::Box, mem}; +use crate::stdlib::{ + any::TypeId, + boxed::Box, + mem, + string::{String, ToString}, +}; /// Trait to register custom functions with the `Engine`. pub trait RegisterFn { diff --git a/src/module.rs b/src/module.rs index c64d16e2..5a6a604c 100644 --- a/src/module.rs +++ b/src/module.rs @@ -25,11 +25,13 @@ use crate::stdlib::{ num::NonZeroUsize, ops::{Deref, DerefMut}, string::{String, ToString}, - sync::RwLock, vec, vec::Vec, }; +#[cfg(not(feature = "no_std"))] +use crate::stdlib::sync::RwLock; + /// Return type of module-level Rust function. pub type FuncReturn = Result>; diff --git a/src/packages/mod.rs b/src/packages/mod.rs index d75e0adc..43ae5f28 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -52,7 +52,7 @@ pub type PackageLibrary = Shared; /// Type containing a collection of `PackageLibrary` instances. /// All function and type iterator keys in the loaded packages are indexed for fast access. -#[derive(Clone, Default)] +#[derive(Debug, Clone, Default)] pub(crate) struct PackagesCollection(StaticVec); impl PackagesCollection { diff --git a/src/settings.rs b/src/settings.rs index e3265c4a..f1967cdf 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -4,6 +4,8 @@ use crate::optimize::OptimizationLevel; use crate::packages::PackageLibrary; use crate::token::is_valid_identifier; +use crate::stdlib::{boxed::Box, format, string::String}; + impl Engine { /// Load a new package into the `Engine`. /// diff --git a/src/stdlib.rs b/src/stdlib.rs index 64eda6fb..5ec6c2a0 100644 --- a/src/stdlib.rs +++ b/src/stdlib.rs @@ -16,7 +16,7 @@ mod inner { pub use core_error as error; pub mod collections { - pub use hashbrown::HashMap; + pub use hashbrown::{HashMap, HashSet}; } } diff --git a/src/syntax.rs b/src/syntax.rs index 62aa20bd..3b646d25 100644 --- a/src/syntax.rs +++ b/src/syntax.rs @@ -75,7 +75,7 @@ impl Engine { ) -> Result> + SendSync + 'static, - ) -> Result> { + ) -> Result<&mut Self, Box> { if value.is_empty() { return Err(Box::new(LexError::ImproperSymbol("".to_string()))); } diff --git a/src/token.rs b/src/token.rs index 460ddcb5..88196856 100644 --- a/src/token.rs +++ b/src/token.rs @@ -13,7 +13,7 @@ use crate::stdlib::{ boxed::Box, char, collections::HashMap, - fmt, + fmt, format, iter::Peekable, str::{Chars, FromStr}, string::{String, ToString}, diff --git a/tests/call_fn.rs b/tests/call_fn.rs index 62291830..2eecab90 100644 --- a/tests/call_fn.rs +++ b/tests/call_fn.rs @@ -115,6 +115,7 @@ fn test_anonymous_fn() -> Result<(), Box> { } #[test] +#[cfg(not(feature = "no_object"))] fn test_fn_ptr() -> Result<(), Box> { let mut engine = Engine::new(); diff --git a/tests/tokens.rs b/tests/tokens.rs index bb033619..f54afa84 100644 --- a/tests/tokens.rs +++ b/tests/tokens.rs @@ -35,6 +35,7 @@ fn test_tokens_custom_operator() -> Result<(), Box> { 15 ); + #[cfg(not(feature = "no_function"))] assert_eq!( engine.eval::( r"