Fix builds.

This commit is contained in:
Stephen Chung 2022-11-23 17:23:54 +08:00
parent 3e7408511e
commit 02ef119603
9 changed files with 92 additions and 56 deletions

View File

@ -1,7 +1,8 @@
//! Module that defines the public compilation API of [`Engine`]. //! Module that defines the public compilation API of [`Engine`].
use crate::parser::{ParseResult, ParseState}; use crate::parser::{ParseResult, ParseState};
use crate::{Engine, OptimizationLevel, Scope, StringsInterner, AST}; use crate::types::StringsInterner;
use crate::{Engine, OptimizationLevel, Scope, AST};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;

View File

@ -2,10 +2,9 @@
use crate::eval::{Caches, GlobalRuntimeState}; use crate::eval::{Caches, GlobalRuntimeState};
use crate::parser::ParseState; use crate::parser::ParseState;
use crate::types::dynamic::Variant; use crate::types::{dynamic::Variant, StringsInterner};
use crate::{ use crate::{
reify, Dynamic, Engine, OptimizationLevel, Position, RhaiResult, RhaiResultOf, Scope, reify, Dynamic, Engine, OptimizationLevel, Position, RhaiResult, RhaiResultOf, Scope, AST, ERR,
StringsInterner, AST, ERR,
}; };
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;

View File

@ -3,7 +3,8 @@
use crate::parser::{ParseSettingFlags, ParseState}; use crate::parser::{ParseSettingFlags, ParseState};
use crate::tokenizer::Token; use crate::tokenizer::Token;
use crate::{Engine, LexError, Map, OptimizationLevel, RhaiResultOf, Scope, StringsInterner}; use crate::types::StringsInterner;
use crate::{Engine, LexError, Map, OptimizationLevel, RhaiResultOf, Scope};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;

View File

@ -1,7 +1,6 @@
//! Module that defines the public function/module registration API of [`Engine`]. //! Module that defines the public function/module registration API of [`Engine`].
use crate::func::{FnCallArgs, RegisterNativeFunction, SendSync}; use crate::func::{FnCallArgs, RegisterNativeFunction, SendSync};
use crate::module::ModuleFlags;
use crate::types::dynamic::Variant; use crate::types::dynamic::Variant;
use crate::{ use crate::{
Engine, FnAccess, FnNamespace, Identifier, Module, NativeCallContext, RhaiResultOf, Shared, Engine, FnAccess, FnNamespace, Identifier, Module, NativeCallContext, RhaiResultOf, Shared,
@ -743,9 +742,9 @@ impl Engine {
} }
let exclude_flags = if include_packages { let exclude_flags = if include_packages {
ModuleFlags::INTERNAL crate::module::ModuleFlags::INTERNAL
} else { } else {
ModuleFlags::INTERNAL | ModuleFlags::STANDARD_LIB crate::module::ModuleFlags::INTERNAL | crate::module::ModuleFlags::STANDARD_LIB
}; };
signatures.extend( signatures.extend(

View File

@ -2,7 +2,8 @@
use crate::eval::{Caches, GlobalRuntimeState}; use crate::eval::{Caches, GlobalRuntimeState};
use crate::parser::ParseState; use crate::parser::ParseState;
use crate::{Engine, RhaiResultOf, Scope, StringsInterner, AST}; use crate::types::StringsInterner;
use crate::{Engine, RhaiResultOf, Scope, AST};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;

View File

@ -311,7 +311,7 @@ impl Module {
dynamic_functions_filter: BloomFilterU64::new(), dynamic_functions_filter: BloomFilterU64::new(),
type_iterators: None, type_iterators: None,
all_type_iterators: None, all_type_iterators: None,
flags: ModuleFlags::empty(), flags: ModuleFlags::INDEXED,
} }
} }

View File

@ -1,7 +1,6 @@
//! Implementations of [`serde::Deserialize`]. //! Implementations of [`serde::Deserialize`].
use crate::{Dynamic, Identifier, ImmutableString, Scope, INT}; use crate::{Dynamic, Identifier, ImmutableString, Scope, INT};
use num_traits::FromPrimitive;
use serde::{ use serde::{
de::{Error, SeqAccess, Visitor}, de::{Error, SeqAccess, Visitor},
Deserialize, Deserializer, Deserialize, Deserializer,
@ -10,6 +9,9 @@ use std::fmt;
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
#[cfg(feature = "decimal")]
use num_traits::FromPrimitive;
struct DynamicVisitor; struct DynamicVisitor;
impl<'de> Visitor<'de> for DynamicVisitor { impl<'de> Visitor<'de> for DynamicVisitor {
@ -56,7 +58,7 @@ impl<'de> Visitor<'de> for DynamicVisitor {
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
return Ok(Dynamic::from_float(v as crate::FLOAT)); return Ok(Dynamic::from_float(v as crate::FLOAT));
Err(Error::custom(format!("integer number too large: {}", v))) Err(Error::custom(format!("integer number too large: {v}")))
} }
} }
#[inline] #[inline]
@ -75,7 +77,7 @@ impl<'de> Visitor<'de> for DynamicVisitor {
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
return Ok(Dynamic::from_float(v as crate::FLOAT)); return Ok(Dynamic::from_float(v as crate::FLOAT));
Err(Error::custom(format!("integer number too large: {}", v))) Err(Error::custom(format!("integer number too large: {v}")))
} }
} }
#[inline(always)] #[inline(always)]
@ -106,7 +108,7 @@ impl<'de> Visitor<'de> for DynamicVisitor {
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
return Ok(Dynamic::from_float(v as crate::FLOAT)); return Ok(Dynamic::from_float(v as crate::FLOAT));
Err(Error::custom(format!("integer number too large: {}", v))) Err(Error::custom(format!("integer number too large: {v}")))
} }
} }
#[inline] #[inline]
@ -124,7 +126,7 @@ impl<'de> Visitor<'de> for DynamicVisitor {
return Ok(Dynamic::from_float(v as crate::FLOAT)); return Ok(Dynamic::from_float(v as crate::FLOAT));
#[allow(unreachable_code)] #[allow(unreachable_code)]
Err(Error::custom(format!("integer number too large: {}", v))) Err(Error::custom(format!("integer number too large: {v}")))
} }
#[inline] #[inline]
fn visit_u128<E: Error>(self, v: u128) -> Result<Self::Value, E> { fn visit_u128<E: Error>(self, v: u128) -> Result<Self::Value, E> {
@ -141,18 +143,44 @@ impl<'de> Visitor<'de> for DynamicVisitor {
return Ok(Dynamic::from_float(v as crate::FLOAT)); return Ok(Dynamic::from_float(v as crate::FLOAT));
#[allow(unreachable_code)] #[allow(unreachable_code)]
Err(Error::custom(format!("integer number too large: {}", v))) Err(Error::custom(format!("integer number too large: {v}")))
} }
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
#[inline(always)] #[inline(always)]
fn visit_f32<E: Error>(self, v: f32) -> Result<Self::Value, E> { fn visit_f32<E: Error>(self, v: f32) -> Result<Self::Value, E> {
Ok(crate::FLOAT::from(v).into()) #[cfg(not(feature = "no_float"))]
return Ok((v as crate::FLOAT).into());
#[allow(unreachable_code)]
{
#[cfg(feature = "decimal")]
if let Some(n) = rust_decimal::Decimal::from_f32(v) {
return Ok(Dynamic::from_decimal(n));
}
Err(Error::custom(format!(
"floating-point number is not supported: {v}"
)))
}
} }
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
#[inline(always)] #[inline(always)]
fn visit_f64<E: Error>(self, v: f64) -> Result<Self::Value, E> { fn visit_f64<E: Error>(self, v: f64) -> Result<Self::Value, E> {
Ok(crate::FLOAT::from(v).into()) #[cfg(not(feature = "no_float"))]
return Ok((v as crate::FLOAT).into());
#[allow(unreachable_code)]
{
#[cfg(feature = "decimal")]
if let Some(n) = rust_decimal::Decimal::from_f64(v) {
return Ok(Dynamic::from_decimal(n));
}
Err(Error::custom(format!(
"floating-point number is not supported: {v}"
)))
}
} }
#[cfg(feature = "no_float")] #[cfg(feature = "no_float")]

View File

@ -1,7 +1,6 @@
//! Implement serialization support of [`Dynamic`][crate::Dynamic] for [`serde`]. //! Implement serialization support of [`Dynamic`][crate::Dynamic] for [`serde`].
use crate::{Dynamic, Identifier, Position, RhaiError, RhaiResult, RhaiResultOf, ERR, INT}; use crate::{Dynamic, Identifier, Position, RhaiError, RhaiResult, RhaiResultOf, ERR, INT};
use num_traits::FromPrimitive;
use serde::ser::{ use serde::ser::{
Error, SerializeMap, SerializeSeq, SerializeStruct, SerializeTuple, SerializeTupleStruct, Error, SerializeMap, SerializeSeq, SerializeStruct, SerializeTuple, SerializeTupleStruct,
}; };
@ -10,6 +9,9 @@ use std::fmt;
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
#[cfg(feature = "decimal")]
use num_traits::FromPrimitive;
/// Serializer for [`Dynamic`][crate::Dynamic]. /// Serializer for [`Dynamic`][crate::Dynamic].
pub struct DynamicSerializer { pub struct DynamicSerializer {
/// Buffer to hold a temporary key. /// Buffer to hold a temporary key.
@ -146,7 +148,7 @@ impl Serializer for &mut DynamicSerializer {
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
return Ok(Dynamic::from_float(v as crate::FLOAT)); return Ok(Dynamic::from_float(v as crate::FLOAT));
Err(Error::custom(format!("integer number too large: {}", v))) Err(Error::custom(format!("integer number too large: {v}")))
} }
} }
@ -166,7 +168,7 @@ impl Serializer for &mut DynamicSerializer {
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
return Ok(Dynamic::from_float(v as crate::FLOAT)); return Ok(Dynamic::from_float(v as crate::FLOAT));
Err(Error::custom(format!("integer number too large: {}", v))) Err(Error::custom(format!("integer number too large: {v}")))
} }
} }
@ -200,7 +202,7 @@ impl Serializer for &mut DynamicSerializer {
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
return Ok(Dynamic::from_float(v as crate::FLOAT)); return Ok(Dynamic::from_float(v as crate::FLOAT));
Err(Error::custom(format!("integer number too large: {}", v))) Err(Error::custom(format!("integer number too large: {v}")))
} }
} }
@ -219,7 +221,7 @@ impl Serializer for &mut DynamicSerializer {
return Ok(Dynamic::from_float(v as crate::FLOAT)); return Ok(Dynamic::from_float(v as crate::FLOAT));
#[allow(unreachable_code)] #[allow(unreachable_code)]
Err(Error::custom(format!("integer number too large: {}", v))) Err(Error::custom(format!("integer number too large: {v}")))
} }
#[inline] #[inline]
@ -237,40 +239,43 @@ impl Serializer for &mut DynamicSerializer {
return Ok(Dynamic::from_float(v as crate::FLOAT)); return Ok(Dynamic::from_float(v as crate::FLOAT));
#[allow(unreachable_code)] #[allow(unreachable_code)]
Err(Error::custom(format!("integer number too large: {}", v))) Err(Error::custom(format!("integer number too large: {v}")))
} }
#[cfg(not(feature = "no_float"))]
#[inline(always)] #[inline(always)]
fn serialize_f32(self, v: f32) -> RhaiResultOf<Self::Ok> { fn serialize_f32(self, v: f32) -> RhaiResultOf<Self::Ok> {
Ok(crate::FLOAT::from(v).into()) #[cfg(not(feature = "no_float"))]
return Ok((v as crate::FLOAT).into());
#[allow(unreachable_code)]
{
#[cfg(feature = "decimal")]
if let Some(n) = rust_decimal::Decimal::from_f32(v) {
return Ok(Dynamic::from_decimal(n));
}
Err(Error::custom(format!(
"floating-point number is not supported: {v}"
)))
}
} }
#[cfg(not(feature = "no_float"))]
#[inline(always)] #[inline(always)]
fn serialize_f64(self, v: f64) -> RhaiResultOf<Self::Ok> { fn serialize_f64(self, v: f64) -> RhaiResultOf<Self::Ok> {
Ok(crate::FLOAT::from(v).into()) #[cfg(not(feature = "no_float"))]
} return Ok((v as crate::FLOAT).into());
#[cfg(feature = "no_float")] #[allow(unreachable_code)]
#[cfg(feature = "decimal")] {
#[inline] #[cfg(feature = "decimal")]
fn serialize_f32(self, v: f32) -> RhaiResultOf<Self::Ok> { if let Some(n) = rust_decimal::Decimal::from_f64(v) {
use std::convert::TryFrom; return Ok(Dynamic::from_decimal(n));
}
rust_decimal::Decimal::try_from(v) Err(Error::custom(format!(
.map(|v| v.into()) "floating-point number is not supported: {v}"
.map_err(Error::custom) )))
} }
#[cfg(feature = "no_float")]
#[cfg(feature = "decimal")]
#[inline]
fn serialize_f64(self, v: f64) -> RhaiResultOf<Self::Ok> {
use std::convert::TryFrom;
rust_decimal::Decimal::try_from(v)
.map(|v| v.into())
.map_err(Error::custom)
} }
#[inline(always)] #[inline(always)]

View File

@ -266,16 +266,18 @@ fn test_custom_syntax_raw() -> Result<(), Box<EvalAltResult>> {
*state = Dynamic::FALSE; *state = Dynamic::FALSE;
Ok(Some("$ident$".into())) Ok(Some("$ident$".into()))
} }
2 => match stream[1].as_str() { 2 => {
"world" if state.as_bool().unwrap_or(false) => Ok(Some("$$world".into())), match stream[1].as_str() {
"world" => Ok(Some("$$hello".into())), "world" if state.as_bool().unwrap_or(false) => Ok(Some("$$world".into())),
"kitty" => { "world" => Ok(Some("$$hello".into())),
*state = (42 as INT).into(); "kitty" => {
Ok(None) *state = (42 as INT).into();
Ok(None)
}
s => Err(LexError::ImproperSymbol(s.to_string(), String::new())
.into_err(Position::NONE)),
} }
s => Err(LexError::ImproperSymbol(s.to_string(), String::new()) }
.into_err(Position::NONE)),
},
_ => unreachable!(), _ => unreachable!(),
}, },
true, true,