Skip to content

Commit

Permalink
Merge pull request #185 from schungx/master
Browse files Browse the repository at this point in the history
Fix all features.
  • Loading branch information
schungx committed Jul 13, 2020
2 parents 7a27f3f + adc96e2 commit 15292f4
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 12 deletions.
3 changes: 2 additions & 1 deletion RELEASES.md
Expand Up @@ -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
---------
Expand Down Expand Up @@ -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
==============

Expand Down
6 changes: 4 additions & 2 deletions src/any.rs
Expand Up @@ -212,9 +212,11 @@ pub(crate) fn map_std_type_name(name: &str) -> &str {
"string"
} else if name == type_name::<FnPtr>() {
"Fn"
} else if name == type_name::<Instant>() {
"timestamp"
} else {
#[cfg(not(feature = "no_std"))]
if name == type_name::<Instant>() {
return "timestamp";
}
#[cfg(not(feature = "no_index"))]
if name == type_name::<Array>() {
return "array";
Expand Down
13 changes: 12 additions & 1 deletion src/engine.rs
Expand Up @@ -26,7 +26,7 @@ use crate::stdlib::{
boxed::Box,
collections::{HashMap, HashSet},
convert::TryFrom,
format,
fmt, format,
iter::{empty, once},
mem,
string::{String, ToString},
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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::<Map>() {
if let Some(val) = map.get(fn_name) {
if let Some(f) = val.downcast_ref::<FnPtr>() {
Expand Down
4 changes: 2 additions & 2 deletions src/fn_native.rs
Expand Up @@ -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")]
Expand Down Expand Up @@ -86,7 +86,7 @@ impl TryFrom<ImmutableString> for FnPtr {
Ok(Self(value))
} else {
Err(Box::new(EvalAltResult::ErrorFunctionNotFound(
value.to_string(),
value.into(),
Position::none(),
)))
}
Expand Down
7 changes: 6 additions & 1 deletion src/fn_register.rs
Expand Up @@ -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<FN, ARGS, RET> {
Expand Down
4 changes: 3 additions & 1 deletion src/module.rs
Expand Up @@ -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<T> = Result<T, Box<EvalAltResult>>;

Expand Down
2 changes: 1 addition & 1 deletion src/packages/mod.rs
Expand Up @@ -52,7 +52,7 @@ pub type PackageLibrary = Shared<Module>;

/// 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<PackageLibrary>);

impl PackagesCollection {
Expand Down
2 changes: 2 additions & 0 deletions src/settings.rs
Expand Up @@ -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`.
///
Expand Down
2 changes: 1 addition & 1 deletion src/stdlib.rs
Expand Up @@ -16,7 +16,7 @@ mod inner {
pub use core_error as error;

pub mod collections {
pub use hashbrown::HashMap;
pub use hashbrown::{HashMap, HashSet};
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/syntax.rs
Expand Up @@ -75,7 +75,7 @@ impl Engine {
) -> Result<Dynamic, Box<EvalAltResult>>
+ SendSync
+ 'static,
) -> Result<self, Box<LexError>> {
) -> Result<&mut Self, Box<LexError>> {
if value.is_empty() {
return Err(Box::new(LexError::ImproperSymbol("".to_string())));
}
Expand Down
2 changes: 1 addition & 1 deletion src/token.rs
Expand Up @@ -13,7 +13,7 @@ use crate::stdlib::{
boxed::Box,
char,
collections::HashMap,
fmt,
fmt, format,
iter::Peekable,
str::{Chars, FromStr},
string::{String, ToString},
Expand Down
1 change: 1 addition & 0 deletions tests/call_fn.rs
Expand Up @@ -115,6 +115,7 @@ fn test_anonymous_fn() -> Result<(), Box<EvalAltResult>> {
}

#[test]
#[cfg(not(feature = "no_object"))]
fn test_fn_ptr() -> Result<(), Box<EvalAltResult>> {
let mut engine = Engine::new();

Expand Down
1 change: 1 addition & 0 deletions tests/tokens.rs
Expand Up @@ -35,6 +35,7 @@ fn test_tokens_custom_operator() -> Result<(), Box<EvalAltResult>> {
15
);

#[cfg(not(feature = "no_function"))]
assert_eq!(
engine.eval::<INT>(
r"
Expand Down

0 comments on commit 15292f4

Please sign in to comment.