Fix builds.
This commit is contained in:
parent
83589be58e
commit
a9b6e8b98c
@ -9,7 +9,7 @@ use crate::{Engine, Module, Scope, INT};
|
|||||||
|
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
use std::{any::type_name, borrow::Cow, cmp::Ordering, fmt, fmt::Write};
|
use std::{any::type_name, borrow::Cow, cmp::Ordering, fmt};
|
||||||
|
|
||||||
impl Engine {
|
impl Engine {
|
||||||
/// _(metadata, internals)_ Return [`Definitions`] that can be used to generate definition files
|
/// _(metadata, internals)_ Return [`Definitions`] that can be used to generate definition files
|
||||||
@ -186,6 +186,8 @@ impl Definitions<'_> {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
{
|
{
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
for (module_name, module_def) in self.modules_impl(&config) {
|
for (module_name, module_def) in self.modules_impl(&config) {
|
||||||
write!(
|
write!(
|
||||||
&mut def_file,
|
&mut def_file,
|
||||||
@ -382,6 +384,7 @@ impl Definitions<'_> {
|
|||||||
|
|
||||||
impl Module {
|
impl Module {
|
||||||
/// Return definitions for all items inside the [`Module`].
|
/// Return definitions for all items inside the [`Module`].
|
||||||
|
#[cfg(not(feature = "no_module"))]
|
||||||
fn definition(&self, def: &Definitions) -> String {
|
fn definition(&self, def: &Definitions) -> String {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
self.write_definition(&mut s, def).unwrap();
|
self.write_definition(&mut s, def).unwrap();
|
||||||
|
@ -213,6 +213,7 @@ impl AST {
|
|||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) fn doc_mut(&mut self) -> &mut crate::SmartString {
|
pub(crate) fn doc_mut(&mut self) -> &mut crate::SmartString {
|
||||||
&mut self.doc
|
&mut self.doc
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
use std::{
|
use std::{collections::BTreeSet, fmt, num::NonZeroU8};
|
||||||
collections::{BTreeMap, BTreeSet},
|
|
||||||
fmt,
|
|
||||||
num::NonZeroU8,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub type Precedence = NonZeroU8;
|
pub type Precedence = NonZeroU8;
|
||||||
|
|
||||||
@ -99,7 +95,7 @@ pub struct Engine {
|
|||||||
pub(crate) global_modules: StaticVec<Shared<Module>>,
|
pub(crate) global_modules: StaticVec<Shared<Module>>,
|
||||||
/// A collection of all sub-modules directly loaded into the Engine.
|
/// A collection of all sub-modules directly loaded into the Engine.
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
pub(crate) global_sub_modules: BTreeMap<Identifier, Shared<Module>>,
|
pub(crate) global_sub_modules: std::collections::BTreeMap<Identifier, Shared<Module>>,
|
||||||
|
|
||||||
/// A module resolution service.
|
/// A module resolution service.
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
@ -112,10 +108,11 @@ pub struct Engine {
|
|||||||
pub(crate) disabled_symbols: BTreeSet<Identifier>,
|
pub(crate) disabled_symbols: BTreeSet<Identifier>,
|
||||||
/// A map containing custom keywords and precedence to recognize.
|
/// A map containing custom keywords and precedence to recognize.
|
||||||
#[cfg(not(feature = "no_custom_syntax"))]
|
#[cfg(not(feature = "no_custom_syntax"))]
|
||||||
pub(crate) custom_keywords: BTreeMap<Identifier, Option<Precedence>>,
|
pub(crate) custom_keywords: std::collections::BTreeMap<Identifier, Option<Precedence>>,
|
||||||
/// Custom syntax.
|
/// Custom syntax.
|
||||||
#[cfg(not(feature = "no_custom_syntax"))]
|
#[cfg(not(feature = "no_custom_syntax"))]
|
||||||
pub(crate) custom_syntax: BTreeMap<Identifier, crate::api::custom_syntax::CustomSyntax>,
|
pub(crate) custom_syntax:
|
||||||
|
std::collections::BTreeMap<Identifier, crate::api::custom_syntax::CustomSyntax>,
|
||||||
/// Callback closure for filtering variable definition.
|
/// Callback closure for filtering variable definition.
|
||||||
pub(crate) def_var_filter: Option<Box<OnDefVarCallback>>,
|
pub(crate) def_var_filter: Option<Box<OnDefVarCallback>>,
|
||||||
/// Callback closure for resolving variable access.
|
/// Callback closure for resolving variable access.
|
||||||
@ -265,7 +262,7 @@ impl Engine {
|
|||||||
global_modules: StaticVec::new_const(),
|
global_modules: StaticVec::new_const(),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
global_sub_modules: BTreeMap::new(),
|
global_sub_modules: std::collections::BTreeMap::new(),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
module_resolver: Box::new(crate::module::resolvers::DummyModuleResolver::new()),
|
module_resolver: Box::new(crate::module::resolvers::DummyModuleResolver::new()),
|
||||||
@ -273,9 +270,9 @@ impl Engine {
|
|||||||
interned_strings: StringsInterner::new().into(),
|
interned_strings: StringsInterner::new().into(),
|
||||||
disabled_symbols: BTreeSet::new(),
|
disabled_symbols: BTreeSet::new(),
|
||||||
#[cfg(not(feature = "no_custom_syntax"))]
|
#[cfg(not(feature = "no_custom_syntax"))]
|
||||||
custom_keywords: BTreeMap::new(),
|
custom_keywords: std::collections::BTreeMap::new(),
|
||||||
#[cfg(not(feature = "no_custom_syntax"))]
|
#[cfg(not(feature = "no_custom_syntax"))]
|
||||||
custom_syntax: BTreeMap::new(),
|
custom_syntax: std::collections::BTreeMap::new(),
|
||||||
|
|
||||||
def_var_filter: None,
|
def_var_filter: None,
|
||||||
resolve_var: None,
|
resolve_var: None,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Global runtime state.
|
//! Global runtime state.
|
||||||
|
|
||||||
use crate::{Dynamic, Engine, Identifier, ImmutableString};
|
use crate::{Dynamic, Engine, Identifier};
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
use std::{fmt, marker::PhantomData};
|
use std::{fmt, marker::PhantomData};
|
||||||
@ -9,7 +9,7 @@ use std::{fmt, marker::PhantomData};
|
|||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
pub type GlobalConstants =
|
pub type GlobalConstants =
|
||||||
crate::Shared<crate::Locked<std::collections::BTreeMap<ImmutableString, Dynamic>>>;
|
crate::Shared<crate::Locked<std::collections::BTreeMap<crate::ImmutableString, Dynamic>>>;
|
||||||
|
|
||||||
/// _(internals)_ Global runtime states.
|
/// _(internals)_ Global runtime states.
|
||||||
/// Exported under the `internals` feature only.
|
/// Exported under the `internals` feature only.
|
||||||
@ -25,7 +25,7 @@ pub type GlobalConstants =
|
|||||||
pub struct GlobalRuntimeState<'a> {
|
pub struct GlobalRuntimeState<'a> {
|
||||||
/// Stack of module names.
|
/// Stack of module names.
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
keys: crate::StaticVec<ImmutableString>,
|
keys: crate::StaticVec<crate::ImmutableString>,
|
||||||
/// Stack of imported [modules][crate::Module].
|
/// Stack of imported [modules][crate::Module].
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
modules: crate::StaticVec<crate::Shared<crate::Module>>,
|
modules: crate::StaticVec<crate::Shared<crate::Module>>,
|
||||||
@ -169,7 +169,7 @@ impl GlobalRuntimeState<'_> {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn push_import(
|
pub fn push_import(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: impl Into<ImmutableString>,
|
name: impl Into<crate::ImmutableString>,
|
||||||
module: impl Into<crate::Shared<crate::Module>>,
|
module: impl Into<crate::Shared<crate::Module>>,
|
||||||
) {
|
) {
|
||||||
self.keys.push(name.into());
|
self.keys.push(name.into());
|
||||||
@ -205,7 +205,7 @@ impl GlobalRuntimeState<'_> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn iter_imports_raw(
|
pub(crate) fn iter_imports_raw(
|
||||||
&self,
|
&self,
|
||||||
) -> impl Iterator<Item = (&ImmutableString, &crate::Shared<crate::Module>)> {
|
) -> impl Iterator<Item = (&crate::ImmutableString, &crate::Shared<crate::Module>)> {
|
||||||
self.keys.iter().rev().zip(self.modules.iter().rev())
|
self.keys.iter().rev().zip(self.modules.iter().rev())
|
||||||
}
|
}
|
||||||
/// Get an iterator to the stack of globally-imported [modules][crate::Module] in forward order.
|
/// Get an iterator to the stack of globally-imported [modules][crate::Module] in forward order.
|
||||||
@ -216,7 +216,7 @@ impl GlobalRuntimeState<'_> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn scan_imports_raw(
|
pub fn scan_imports_raw(
|
||||||
&self,
|
&self,
|
||||||
) -> impl Iterator<Item = (&ImmutableString, &crate::Shared<crate::Module>)> {
|
) -> impl Iterator<Item = (&crate::ImmutableString, &crate::Shared<crate::Module>)> {
|
||||||
self.keys.iter().zip(self.modules.iter())
|
self.keys.iter().zip(self.modules.iter())
|
||||||
}
|
}
|
||||||
/// Does the specified function hash key exist in the stack of globally-imported
|
/// Does the specified function hash key exist in the stack of globally-imported
|
||||||
@ -310,9 +310,9 @@ impl GlobalRuntimeState<'_> {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
impl IntoIterator for GlobalRuntimeState<'_> {
|
impl IntoIterator for GlobalRuntimeState<'_> {
|
||||||
type Item = (ImmutableString, crate::Shared<crate::Module>);
|
type Item = (crate::ImmutableString, crate::Shared<crate::Module>);
|
||||||
type IntoIter = std::iter::Zip<
|
type IntoIter = std::iter::Zip<
|
||||||
std::iter::Rev<smallvec::IntoIter<[ImmutableString; 3]>>,
|
std::iter::Rev<smallvec::IntoIter<[crate::ImmutableString; 3]>>,
|
||||||
std::iter::Rev<smallvec::IntoIter<[crate::Shared<crate::Module>; 3]>>,
|
std::iter::Rev<smallvec::IntoIter<[crate::Shared<crate::Module>; 3]>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
@ -327,9 +327,9 @@ impl IntoIterator for GlobalRuntimeState<'_> {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> {
|
impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> {
|
||||||
type Item = (&'a ImmutableString, &'a crate::Shared<crate::Module>);
|
type Item = (&'a crate::ImmutableString, &'a crate::Shared<crate::Module>);
|
||||||
type IntoIter = std::iter::Zip<
|
type IntoIter = std::iter::Zip<
|
||||||
std::iter::Rev<std::slice::Iter<'a, ImmutableString>>,
|
std::iter::Rev<std::slice::Iter<'a, crate::ImmutableString>>,
|
||||||
std::iter::Rev<std::slice::Iter<'a, crate::Shared<crate::Module>>>,
|
std::iter::Rev<std::slice::Iter<'a, crate::Shared<crate::Module>>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
@ -341,7 +341,7 @@ impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
impl<K: Into<ImmutableString>, M: Into<crate::Shared<crate::Module>>> Extend<(K, M)>
|
impl<K: Into<crate::ImmutableString>, M: Into<crate::Shared<crate::Module>>> Extend<(K, M)>
|
||||||
for GlobalRuntimeState<'_>
|
for GlobalRuntimeState<'_>
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::def_package;
|
use crate::def_package;
|
||||||
use crate::plugin::*;
|
use crate::plugin::*;
|
||||||
use crate::types::{dynamic::Tag, StringsInterner};
|
use crate::types::dynamic::Tag;
|
||||||
use crate::{Dynamic, RhaiResultOf, ERR, INT};
|
use crate::{Dynamic, RhaiResultOf, ERR, INT};
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
@ -129,12 +129,12 @@ fn collect_fn_metadata(
|
|||||||
filter: impl Fn(FnNamespace, FnAccess, &str, usize, &crate::Shared<crate::ast::ScriptFnDef>) -> bool
|
filter: impl Fn(FnNamespace, FnAccess, &str, usize, &crate::Shared<crate::ast::ScriptFnDef>) -> bool
|
||||||
+ Copy,
|
+ Copy,
|
||||||
) -> crate::Array {
|
) -> crate::Array {
|
||||||
use crate::{ast::ScriptFnDef, Array, Identifier, Map};
|
use crate::{ast::ScriptFnDef, Array, Map};
|
||||||
|
|
||||||
// Create a metadata record for a function.
|
// Create a metadata record for a function.
|
||||||
fn make_metadata(
|
fn make_metadata(
|
||||||
dict: &mut StringsInterner,
|
dict: &mut crate::types::StringsInterner,
|
||||||
#[cfg(not(feature = "no_module"))] namespace: Identifier,
|
#[cfg(not(feature = "no_module"))] namespace: crate::Identifier,
|
||||||
func: &ScriptFnDef,
|
func: &ScriptFnDef,
|
||||||
) -> Map {
|
) -> Map {
|
||||||
let mut map = Map::new();
|
let mut map = Map::new();
|
||||||
@ -179,7 +179,7 @@ fn collect_fn_metadata(
|
|||||||
map
|
map
|
||||||
}
|
}
|
||||||
|
|
||||||
let dict = &mut StringsInterner::new();
|
let dict = &mut crate::types::StringsInterner::new();
|
||||||
let mut list = Array::new();
|
let mut list = Array::new();
|
||||||
|
|
||||||
ctx.iter_namespaces()
|
ctx.iter_namespaces()
|
||||||
@ -190,7 +190,7 @@ fn collect_fn_metadata(
|
|||||||
make_metadata(
|
make_metadata(
|
||||||
dict,
|
dict,
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
Identifier::new_const(),
|
crate::Identifier::new_const(),
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
@ -207,7 +207,7 @@ fn collect_fn_metadata(
|
|||||||
make_metadata(
|
make_metadata(
|
||||||
dict,
|
dict,
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
Identifier::new_const(),
|
crate::Identifier::new_const(),
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
@ -225,7 +225,7 @@ fn collect_fn_metadata(
|
|||||||
make_metadata(
|
make_metadata(
|
||||||
dict,
|
dict,
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
Identifier::new_const(),
|
crate::Identifier::new_const(),
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
@ -236,7 +236,7 @@ fn collect_fn_metadata(
|
|||||||
{
|
{
|
||||||
// Recursively scan modules for script-defined functions.
|
// Recursively scan modules for script-defined functions.
|
||||||
fn scan_module(
|
fn scan_module(
|
||||||
dict: &mut StringsInterner,
|
dict: &mut crate::types::StringsInterner,
|
||||||
list: &mut Array,
|
list: &mut Array,
|
||||||
namespace: &str,
|
namespace: &str,
|
||||||
module: &Module,
|
module: &Module,
|
||||||
|
@ -83,6 +83,7 @@ pub trait Package {
|
|||||||
///
|
///
|
||||||
/// package.register_into_engine_as(&mut engine, "core");
|
/// package.register_into_engine_as(&mut engine, "core");
|
||||||
/// ```
|
/// ```
|
||||||
|
#[cfg(not(feature = "no_module"))]
|
||||||
fn register_into_engine_as(&self, engine: &mut Engine, name: &str) -> &Self {
|
fn register_into_engine_as(&self, engine: &mut Engine, name: &str) -> &Self {
|
||||||
Self::init_engine(engine);
|
Self::init_engine(engine);
|
||||||
engine.register_static_module(name, self.as_shared_module());
|
engine.register_static_module(name, self.as_shared_module());
|
||||||
|
@ -187,12 +187,13 @@ impl<'e> ParseState<'e> {
|
|||||||
lib: &FnLib,
|
lib: &FnLib,
|
||||||
pos: Position,
|
pos: Position,
|
||||||
) -> (Option<NonZeroUsize>, bool) {
|
) -> (Option<NonZeroUsize>, bool) {
|
||||||
|
let _lib = lib;
|
||||||
let _pos = pos;
|
let _pos = pos;
|
||||||
|
|
||||||
let (index, hit_barrier) = self.find_var(name);
|
let (index, hit_barrier) = self.find_var(name);
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
let is_func_name = lib.values().any(|f| f.name == name);
|
let is_func_name = _lib.values().any(|f| f.name == name);
|
||||||
|
|
||||||
#[cfg(feature = "no_function")]
|
#[cfg(feature = "no_function")]
|
||||||
let is_func_name = false;
|
let is_func_name = false;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#![cfg(feature = "metadata")]
|
#![cfg(feature = "metadata")]
|
||||||
|
|
||||||
use crate::module::{calc_native_fn_hash, FuncInfo};
|
use crate::module::{calc_native_fn_hash, FuncInfo};
|
||||||
use crate::{calc_fn_hash, Engine, FnAccess, FnNamespace, SmartString, StaticVec, AST};
|
use crate::{calc_fn_hash, Engine, FnAccess, SmartString, StaticVec, AST};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
@ -30,7 +30,7 @@ struct FnMetadata<'a> {
|
|||||||
pub base_hash: u64,
|
pub base_hash: u64,
|
||||||
pub full_hash: u64,
|
pub full_hash: u64,
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
pub namespace: FnNamespace,
|
pub namespace: crate::FnNamespace,
|
||||||
pub access: FnAccess,
|
pub access: FnAccess,
|
||||||
pub name: &'a str,
|
pub name: &'a str,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
@ -184,7 +184,7 @@ pub fn gen_metadata_to_json(
|
|||||||
let mut meta: FnMetadata = f.into();
|
let mut meta: FnMetadata = f.into();
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
{
|
{
|
||||||
meta.namespace = FnNamespace::Global;
|
meta.namespace = crate::FnNamespace::Global;
|
||||||
}
|
}
|
||||||
global.functions.push(meta);
|
global.functions.push(meta);
|
||||||
});
|
});
|
||||||
@ -196,7 +196,7 @@ pub fn gen_metadata_to_json(
|
|||||||
let mut meta: FnMetadata = f.into();
|
let mut meta: FnMetadata = f.into();
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
{
|
{
|
||||||
meta.namespace = FnNamespace::Global;
|
meta.namespace = crate::FnNamespace::Global;
|
||||||
}
|
}
|
||||||
global.functions.push(meta);
|
global.functions.push(meta);
|
||||||
}
|
}
|
||||||
|
@ -333,22 +333,29 @@ impl Span {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Span {
|
impl fmt::Display for Span {
|
||||||
|
#[inline]
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let _f = f;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_position"))]
|
||||||
match (self.start(), self.end()) {
|
match (self.start(), self.end()) {
|
||||||
(Position::NONE, Position::NONE) => write!(f, "{:?}", Position::NONE),
|
(Position::NONE, Position::NONE) => write!(_f, "{:?}", Position::NONE),
|
||||||
(Position::NONE, end) => write!(f, "..{:?}", end),
|
(Position::NONE, end) => write!(_f, "..{:?}", end),
|
||||||
(start, Position::NONE) => write!(f, "{:?}", start),
|
(start, Position::NONE) => write!(_f, "{:?}", start),
|
||||||
(start, end) if start.line() != end.line() => {
|
(start, end) if start.line() != end.line() => {
|
||||||
write!(f, "{:?}-{:?}", start, end)
|
write!(_f, "{:?}-{:?}", start, end)
|
||||||
}
|
}
|
||||||
(start, end) => write!(
|
(start, end) => write!(
|
||||||
f,
|
_f,
|
||||||
"{}:{}-{}",
|
"{}:{}-{}",
|
||||||
start.line().unwrap(),
|
start.line().unwrap(),
|
||||||
start.position().unwrap_or(0),
|
start.position().unwrap_or(0),
|
||||||
end.position().unwrap_or(0)
|
end.position().unwrap_or(0)
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "no_position")]
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Helper module which defines the [`Dynamic`] data type and the
|
//! Helper module which defines the [`Dynamic`] data type and the
|
||||||
//! [`Any`] trait to to allow custom type handling.
|
//! [`Any`] trait to to allow custom type handling.
|
||||||
|
|
||||||
use crate::func::{locked_read, SendSync};
|
use crate::func::SendSync;
|
||||||
use crate::{reify, ExclusiveRange, FnPtr, ImmutableString, InclusiveRange, INT};
|
use crate::{reify, ExclusiveRange, FnPtr, ImmutableString, InclusiveRange, INT};
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
@ -23,6 +23,7 @@ pub use std::time::Instant;
|
|||||||
pub use instant::Instant;
|
pub use instant::Instant;
|
||||||
|
|
||||||
/// The message: data type was checked
|
/// The message: data type was checked
|
||||||
|
#[allow(dead_code)]
|
||||||
const CHECKED: &str = "data type was checked";
|
const CHECKED: &str = "data type was checked";
|
||||||
|
|
||||||
mod private {
|
mod private {
|
||||||
@ -427,7 +428,7 @@ impl Dynamic {
|
|||||||
Union::Variant(ref v, ..) => (***v).type_id(),
|
Union::Variant(ref v, ..) => (***v).type_id(),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Union::Shared(ref cell, ..) => (*locked_read(cell)).type_id(),
|
Union::Shared(ref cell, ..) => (*crate::func::locked_read(cell)).type_id(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Get the name of the type of the value held by this [`Dynamic`].
|
/// Get the name of the type of the value held by this [`Dynamic`].
|
||||||
@ -501,7 +502,7 @@ impl Hash for Dynamic {
|
|||||||
Union::FnPtr(ref f, ..) => f.hash(state),
|
Union::FnPtr(ref f, ..) => f.hash(state),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Union::Shared(ref cell, ..) => (*locked_read(cell)).hash(state),
|
Union::Shared(ref cell, ..) => (*crate::func::locked_read(cell)).hash(state),
|
||||||
|
|
||||||
Union::Variant(..) => unimplemented!("{} cannot be hashed", self.type_name()),
|
Union::Variant(..) => unimplemented!("{} cannot be hashed", self.type_name()),
|
||||||
|
|
||||||
@ -1073,7 +1074,7 @@ impl Dynamic {
|
|||||||
pub fn is_read_only(&self) -> bool {
|
pub fn is_read_only(&self) -> bool {
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
if let Union::Shared(ref cell, ..) = self.0 {
|
if let Union::Shared(ref cell, ..) = self.0 {
|
||||||
return match locked_read(cell).access_mode() {
|
return match crate::func::locked_read(cell).access_mode() {
|
||||||
ReadWrite => false,
|
ReadWrite => false,
|
||||||
ReadOnly => true,
|
ReadOnly => true,
|
||||||
};
|
};
|
||||||
@ -1102,7 +1103,7 @@ impl Dynamic {
|
|||||||
Union::Map(..) => true,
|
Union::Map(..) => true,
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Union::Shared(ref cell, ..) => locked_read(cell).is_hashable(),
|
Union::Shared(ref cell, ..) => crate::func::locked_read(cell).is_hashable(),
|
||||||
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
@ -1353,7 +1354,7 @@ impl Dynamic {
|
|||||||
pub fn flatten_clone(&self) -> Self {
|
pub fn flatten_clone(&self) -> Self {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Union::Shared(ref cell, ..) => locked_read(cell).clone(),
|
Union::Shared(ref cell, ..) => crate::func::locked_read(cell).clone(),
|
||||||
_ => self.clone(),
|
_ => self.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1369,7 +1370,7 @@ impl Dynamic {
|
|||||||
match self.0 {
|
match self.0 {
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Union::Shared(cell, ..) => crate::func::shared_try_take(cell).map_or_else(
|
Union::Shared(cell, ..) => crate::func::shared_try_take(cell).map_or_else(
|
||||||
|ref cell| locked_read(cell).clone(),
|
|ref cell| crate::func::locked_read(cell).clone(),
|
||||||
#[cfg(not(feature = "sync"))]
|
#[cfg(not(feature = "sync"))]
|
||||||
|value| value.into_inner(),
|
|value| value.into_inner(),
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
@ -1391,7 +1392,7 @@ impl Dynamic {
|
|||||||
Union::Shared(ref mut cell, ..) => {
|
Union::Shared(ref mut cell, ..) => {
|
||||||
let cell = mem::take(cell);
|
let cell = mem::take(cell);
|
||||||
*self = crate::func::shared_try_take(cell).map_or_else(
|
*self = crate::func::shared_try_take(cell).map_or_else(
|
||||||
|ref cell| locked_read(cell).clone(),
|
|ref cell| crate::func::locked_read(cell).clone(),
|
||||||
#[cfg(not(feature = "sync"))]
|
#[cfg(not(feature = "sync"))]
|
||||||
|value| value.into_inner(),
|
|value| value.into_inner(),
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
@ -1440,7 +1441,7 @@ impl Dynamic {
|
|||||||
match self.0 {
|
match self.0 {
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Union::Shared(ref cell, ..) => {
|
Union::Shared(ref cell, ..) => {
|
||||||
let value = locked_read(cell);
|
let value = crate::func::locked_read(cell);
|
||||||
|
|
||||||
return if (*value).type_id() != TypeId::of::<T>()
|
return if (*value).type_id() != TypeId::of::<T>()
|
||||||
&& TypeId::of::<Dynamic>() != TypeId::of::<T>()
|
&& TypeId::of::<Dynamic>() != TypeId::of::<T>()
|
||||||
@ -1788,7 +1789,7 @@ impl Dynamic {
|
|||||||
Union::Str(s, ..) => Ok(s),
|
Union::Str(s, ..) => Ok(s),
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Union::Shared(ref cell, ..) => {
|
Union::Shared(ref cell, ..) => {
|
||||||
let value = locked_read(cell);
|
let value = crate::func::locked_read(cell);
|
||||||
|
|
||||||
match value.0 {
|
match value.0 {
|
||||||
Union::Str(ref s, ..) => Ok(s.clone()),
|
Union::Str(ref s, ..) => Ok(s.clone()),
|
||||||
@ -1807,7 +1808,7 @@ impl Dynamic {
|
|||||||
Union::Array(a, ..) => Ok(*a),
|
Union::Array(a, ..) => Ok(*a),
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Union::Shared(ref cell, ..) => {
|
Union::Shared(ref cell, ..) => {
|
||||||
let value = locked_read(cell);
|
let value = crate::func::locked_read(cell);
|
||||||
|
|
||||||
match value.0 {
|
match value.0 {
|
||||||
Union::Array(ref a, ..) => Ok(a.as_ref().clone()),
|
Union::Array(ref a, ..) => Ok(a.as_ref().clone()),
|
||||||
@ -1842,7 +1843,7 @@ impl Dynamic {
|
|||||||
Union::Blob(..) if TypeId::of::<T>() == TypeId::of::<u8>() => Ok(self.cast::<Vec<T>>()),
|
Union::Blob(..) if TypeId::of::<T>() == TypeId::of::<u8>() => Ok(self.cast::<Vec<T>>()),
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Union::Shared(ref cell, ..) => {
|
Union::Shared(ref cell, ..) => {
|
||||||
let value = locked_read(cell);
|
let value = crate::func::locked_read(cell);
|
||||||
|
|
||||||
match value.0 {
|
match value.0 {
|
||||||
Union::Array(ref a, ..) => {
|
Union::Array(ref a, ..) => {
|
||||||
@ -1880,7 +1881,7 @@ impl Dynamic {
|
|||||||
Union::Blob(a, ..) => Ok(*a),
|
Union::Blob(a, ..) => Ok(*a),
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Union::Shared(ref cell, ..) => {
|
Union::Shared(ref cell, ..) => {
|
||||||
let value = locked_read(cell);
|
let value = crate::func::locked_read(cell);
|
||||||
|
|
||||||
match value.0 {
|
match value.0 {
|
||||||
Union::Blob(ref a, ..) => Ok(a.as_ref().clone()),
|
Union::Blob(ref a, ..) => Ok(a.as_ref().clone()),
|
||||||
|
@ -127,6 +127,7 @@ impl StringsInterner<'_> {
|
|||||||
/// Number of strings interned.
|
/// Number of strings interned.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
self.strings.len()
|
self.strings.len()
|
||||||
}
|
}
|
||||||
@ -134,12 +135,14 @@ impl StringsInterner<'_> {
|
|||||||
/// Returns `true` if there are no interned strings.
|
/// Returns `true` if there are no interned strings.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.strings.is_empty()
|
self.strings.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear all interned strings.
|
/// Clear all interned strings.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
self.strings.clear();
|
self.strings.clear();
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ def_package! {
|
|||||||
m.set_native_fn("hello", |x: INT| Ok(x + 1));
|
m.set_native_fn("hello", |x: INT| Ok(x + 1));
|
||||||
m.set_native_fn("@", |x: INT, y: INT| Ok(x * x + y * y));
|
m.set_native_fn("@", |x: INT, y: INT| Ok(x * x + y * y));
|
||||||
} |> |engine| {
|
} |> |engine| {
|
||||||
|
#[cfg(not(feature = "no_custom_syntax"))]
|
||||||
engine.register_custom_operator("@", 160).unwrap();
|
engine.register_custom_operator("@", 160).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,11 +31,20 @@ fn test_packages() -> Result<(), Box<EvalAltResult>> {
|
|||||||
scope.push("x", x);
|
scope.push("x", x);
|
||||||
|
|
||||||
// Evaluate script.
|
// Evaluate script.
|
||||||
engine.eval_with_scope::<INT>(&mut scope, "hello(x) @ foo::hello(x)")
|
|
||||||
|
#[cfg(not(feature = "no_custom_syntax"))]
|
||||||
|
return engine.eval_with_scope::<INT>(&mut scope, "hello(x) @ foo::hello(x)");
|
||||||
|
|
||||||
|
#[cfg(feature = "no_custom_syntax")]
|
||||||
|
return engine.eval_with_scope::<INT>(&mut scope, "hello(x) + foo::hello(x)");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_custom_syntax"))]
|
||||||
assert_eq!(make_call(42)?, 3698);
|
assert_eq!(make_call(42)?, 3698);
|
||||||
|
|
||||||
|
#[cfg(feature = "no_custom_syntax")]
|
||||||
|
assert_eq!(make_call(42)?, 86);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user