Fix features
This commit is contained in:
parent
d563b878aa
commit
0295e109ad
@ -1,6 +1,6 @@
|
|||||||
//! Main module defining the script evaluation `Engine`.
|
//! Main module defining the script evaluation `Engine`.
|
||||||
|
|
||||||
use crate::any::{map_std_type_name, Dynamic, DynamicWriteLock, Union};
|
use crate::any::{map_std_type_name, Dynamic, Union};
|
||||||
use crate::calc_fn_hash;
|
use crate::calc_fn_hash;
|
||||||
use crate::fn_call::run_builtin_op_assignment;
|
use crate::fn_call::run_builtin_op_assignment;
|
||||||
use crate::fn_native::{CallableFunction, Callback, FnPtr};
|
use crate::fn_native::{CallableFunction, Callback, FnPtr};
|
||||||
@ -31,13 +31,15 @@ use crate::module::resolvers;
|
|||||||
#[cfg(any(not(feature = "no_object"), not(feature = "no_module")))]
|
#[cfg(any(not(feature = "no_object"), not(feature = "no_module")))]
|
||||||
use crate::utils::ImmutableString;
|
use crate::utils::ImmutableString;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_shared"))]
|
||||||
|
use crate::any::DynamicWriteLock;
|
||||||
|
|
||||||
use crate::stdlib::{
|
use crate::stdlib::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
boxed::Box,
|
boxed::Box,
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
fmt, format,
|
fmt, format,
|
||||||
iter::{empty, once},
|
iter::{empty, once},
|
||||||
ops::DerefMut,
|
|
||||||
string::{String, ToString},
|
string::{String, ToString},
|
||||||
vec::Vec,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
@ -45,6 +47,9 @@ use crate::stdlib::{
|
|||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
use crate::stdlib::any::TypeId;
|
use crate::stdlib::any::TypeId;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_shared"))]
|
||||||
|
use crate::stdlib::ops::DerefMut;
|
||||||
|
|
||||||
/// Variable-sized array of `Dynamic` values.
|
/// Variable-sized array of `Dynamic` values.
|
||||||
///
|
///
|
||||||
/// Not available under the `no_index` feature.
|
/// Not available under the `no_index` feature.
|
||||||
@ -126,7 +131,8 @@ pub enum Target<'a> {
|
|||||||
/// The target is a mutable reference to a `Dynamic` value somewhere.
|
/// The target is a mutable reference to a `Dynamic` value somewhere.
|
||||||
Ref(&'a mut Dynamic),
|
Ref(&'a mut Dynamic),
|
||||||
/// The target is a mutable reference to a Shared `Dynamic` value.
|
/// The target is a mutable reference to a Shared `Dynamic` value.
|
||||||
/// It holds the access guard and the original container both for cloning purposes
|
/// It holds both the access guard and the original shared value.
|
||||||
|
#[cfg(not(feature = "no_shared"))]
|
||||||
LockGuard((DynamicWriteLock<'a, Dynamic>, Dynamic)),
|
LockGuard((DynamicWriteLock<'a, Dynamic>, Dynamic)),
|
||||||
/// The target is a temporary `Dynamic` value (i.e. the mutation can cause no side effects).
|
/// The target is a temporary `Dynamic` value (i.e. the mutation can cause no side effects).
|
||||||
Value(Dynamic),
|
Value(Dynamic),
|
||||||
@ -142,6 +148,7 @@ impl Target<'_> {
|
|||||||
pub fn is_ref(&self) -> bool {
|
pub fn is_ref(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Ref(_) => true,
|
Self::Ref(_) => true,
|
||||||
|
#[cfg(not(feature = "no_shared"))]
|
||||||
Self::LockGuard(_) => true,
|
Self::LockGuard(_) => true,
|
||||||
Self::Value(_) => false,
|
Self::Value(_) => false,
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
@ -152,6 +159,7 @@ impl Target<'_> {
|
|||||||
pub fn is_value(&self) -> bool {
|
pub fn is_value(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Ref(_) => false,
|
Self::Ref(_) => false,
|
||||||
|
#[cfg(not(feature = "no_shared"))]
|
||||||
Self::LockGuard(_) => false,
|
Self::LockGuard(_) => false,
|
||||||
Self::Value(_) => true,
|
Self::Value(_) => true,
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
@ -163,6 +171,7 @@ impl Target<'_> {
|
|||||||
pub fn is<T: Variant + Clone>(&self) -> bool {
|
pub fn is<T: Variant + Clone>(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Target::Ref(r) => r.is::<T>(),
|
Target::Ref(r) => r.is::<T>(),
|
||||||
|
#[cfg(not(feature = "no_shared"))]
|
||||||
Target::LockGuard((r, _)) => r.is::<T>(),
|
Target::LockGuard((r, _)) => r.is::<T>(),
|
||||||
Target::Value(r) => r.is::<T>(),
|
Target::Value(r) => r.is::<T>(),
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
@ -173,7 +182,8 @@ impl Target<'_> {
|
|||||||
pub fn clone_into_dynamic(self) -> Dynamic {
|
pub fn clone_into_dynamic(self) -> Dynamic {
|
||||||
match self {
|
match self {
|
||||||
Self::Ref(r) => r.clone(), // Referenced value is cloned
|
Self::Ref(r) => r.clone(), // Referenced value is cloned
|
||||||
Self::LockGuard((_, orig)) => orig, // Return original container of the Shared Dynamic
|
#[cfg(not(feature = "no_shared"))]
|
||||||
|
Self::LockGuard((_, orig)) => orig, // Original value is simply taken
|
||||||
Self::Value(v) => v, // Owned value is simply taken
|
Self::Value(v) => v, // Owned value is simply taken
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
Self::StringChar(_, _, ch) => ch, // Character is taken
|
Self::StringChar(_, _, ch) => ch, // Character is taken
|
||||||
@ -183,6 +193,7 @@ impl Target<'_> {
|
|||||||
pub fn as_mut(&mut self) -> &mut Dynamic {
|
pub fn as_mut(&mut self) -> &mut Dynamic {
|
||||||
match self {
|
match self {
|
||||||
Self::Ref(r) => *r,
|
Self::Ref(r) => *r,
|
||||||
|
#[cfg(not(feature = "no_shared"))]
|
||||||
Self::LockGuard((r, _)) => r.deref_mut(),
|
Self::LockGuard((r, _)) => r.deref_mut(),
|
||||||
Self::Value(ref mut r) => r,
|
Self::Value(ref mut r) => r,
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
@ -194,6 +205,7 @@ impl Target<'_> {
|
|||||||
pub fn set_value(&mut self, new_val: Dynamic) -> Result<(), Box<EvalAltResult>> {
|
pub fn set_value(&mut self, new_val: Dynamic) -> Result<(), Box<EvalAltResult>> {
|
||||||
match self {
|
match self {
|
||||||
Self::Ref(r) => **r = new_val,
|
Self::Ref(r) => **r = new_val,
|
||||||
|
#[cfg(not(feature = "no_shared"))]
|
||||||
Self::LockGuard((r, _)) => **r = new_val,
|
Self::LockGuard((r, _)) => **r = new_val,
|
||||||
Self::Value(_) => {
|
Self::Value(_) => {
|
||||||
return Err(Box::new(EvalAltResult::ErrorAssignmentToUnknownLHS(
|
return Err(Box::new(EvalAltResult::ErrorAssignmentToUnknownLHS(
|
||||||
@ -231,7 +243,7 @@ impl<'a> From<&'a mut Dynamic> for Target<'a> {
|
|||||||
fn from(value: &'a mut Dynamic) -> Self {
|
fn from(value: &'a mut Dynamic) -> Self {
|
||||||
#[cfg(not(feature = "no_shared"))]
|
#[cfg(not(feature = "no_shared"))]
|
||||||
if value.is_shared() {
|
if value.is_shared() {
|
||||||
// cloning is cheap since it holds Arc/Rw under the hood
|
// Cloning is cheap for a shared value
|
||||||
let container = value.clone();
|
let container = value.clone();
|
||||||
return Self::LockGuard((value.write_lock::<Dynamic>().unwrap(), container));
|
return Self::LockGuard((value.write_lock::<Dynamic>().unwrap(), container));
|
||||||
}
|
}
|
||||||
|
16
src/token.rs
16
src/token.rs
@ -1431,20 +1431,18 @@ fn get_identifier(
|
|||||||
/// Is this keyword allowed as a function?
|
/// Is this keyword allowed as a function?
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_keyword_function(name: &str) -> bool {
|
pub fn is_keyword_function(name: &str) -> bool {
|
||||||
let mut result = name == KEYWORD_PRINT
|
#[cfg(not(feature = "no_shared"))]
|
||||||
|
if name == KEYWORD_SHARED || name == KEYWORD_TAKE {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
name == KEYWORD_PRINT
|
||||||
|| name == KEYWORD_DEBUG
|
|| name == KEYWORD_DEBUG
|
||||||
|| name == KEYWORD_TYPE_OF
|
|| name == KEYWORD_TYPE_OF
|
||||||
|| name == KEYWORD_EVAL
|
|| name == KEYWORD_EVAL
|
||||||
|| name == KEYWORD_FN_PTR
|
|| name == KEYWORD_FN_PTR
|
||||||
|| name == KEYWORD_FN_PTR_CALL
|
|| name == KEYWORD_FN_PTR_CALL
|
||||||
|| name == KEYWORD_FN_PTR_CURRY;
|
|| name == KEYWORD_FN_PTR_CURRY
|
||||||
|
|
||||||
#[cfg(not(feature = "no_shared"))]
|
|
||||||
{
|
|
||||||
result = result || name == KEYWORD_SHARED || name == KEYWORD_TAKE;
|
|
||||||
}
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Can this keyword be overridden as a function?
|
/// Can this keyword be overridden as a function?
|
||||||
|
Loading…
Reference in New Issue
Block a user