Fix builds.
This commit is contained in:
parent
62d707ff84
commit
4304da7a47
@ -1,7 +1,7 @@
|
|||||||
//! Evaluation context.
|
//! Evaluation context.
|
||||||
|
|
||||||
use super::{Caches, GlobalRuntimeState};
|
use super::{Caches, GlobalRuntimeState};
|
||||||
use crate::{Dynamic, Engine, Module, Scope};
|
use crate::{Dynamic, Engine, Scope};
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ impl<'a, 's, 'ps, 'g, 'c, 't> EvalContext<'a, 's, 'ps, 'g, 'c, 't> {
|
|||||||
/// in reverse order (i.e. modules imported last come first).
|
/// in reverse order (i.e. modules imported last come first).
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn iter_imports(&self) -> impl Iterator<Item = (&str, &Module)> {
|
pub fn iter_imports(&self) -> impl Iterator<Item = (&str, &crate::Module)> {
|
||||||
self.global.iter_imports()
|
self.global.iter_imports()
|
||||||
}
|
}
|
||||||
/// Custom state kept in a [`Dynamic`].
|
/// Custom state kept in a [`Dynamic`].
|
||||||
@ -104,7 +104,7 @@ impl<'a, 's, 'ps, 'g, 'c, 't> EvalContext<'a, 's, 'ps, 'g, 'c, 't> {
|
|||||||
/// Not available under `no_function`.
|
/// Not available under `no_function`.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn iter_namespaces(&self) -> impl Iterator<Item = &Module> {
|
pub fn iter_namespaces(&self) -> impl Iterator<Item = &crate::Module> {
|
||||||
self.global.lib.iter().map(|m| m.as_ref())
|
self.global.lib.iter().map(|m| m.as_ref())
|
||||||
}
|
}
|
||||||
/// _(internals)_ The current set of namespaces containing definitions of all script-defined functions.
|
/// _(internals)_ The current set of namespaces containing definitions of all script-defined functions.
|
||||||
|
@ -4,7 +4,7 @@ use super::{Caches, EvalContext, GlobalRuntimeState, Target};
|
|||||||
use crate::ast::{Expr, OpAssignment};
|
use crate::ast::{Expr, OpAssignment};
|
||||||
use crate::engine::{KEYWORD_THIS, OP_CONCAT};
|
use crate::engine::{KEYWORD_THIS, OP_CONCAT};
|
||||||
use crate::types::dynamic::AccessMode;
|
use crate::types::dynamic::AccessMode;
|
||||||
use crate::{Dynamic, Engine, Position, RhaiResult, RhaiResultOf, Scope, SharedModule, ERR};
|
use crate::{Dynamic, Engine, Position, RhaiResult, RhaiResultOf, Scope, ERR};
|
||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
@ -18,7 +18,7 @@ impl Engine {
|
|||||||
&self,
|
&self,
|
||||||
global: &GlobalRuntimeState,
|
global: &GlobalRuntimeState,
|
||||||
namespace: &crate::ast::Namespace,
|
namespace: &crate::ast::Namespace,
|
||||||
) -> Option<SharedModule> {
|
) -> Option<crate::SharedModule> {
|
||||||
assert!(!namespace.is_empty());
|
assert!(!namespace.is_empty());
|
||||||
|
|
||||||
let root = namespace.root();
|
let root = namespace.root();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Global runtime state.
|
//! Global runtime state.
|
||||||
|
|
||||||
use crate::{Dynamic, Engine, ImmutableString, SharedModule, StaticVec};
|
use crate::{Dynamic, Engine, ImmutableString};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
@ -25,13 +25,13 @@ pub type GlobalConstants =
|
|||||||
pub struct GlobalRuntimeState {
|
pub struct GlobalRuntimeState {
|
||||||
/// Names of imported [modules][crate::Module].
|
/// Names of imported [modules][crate::Module].
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
imports: StaticVec<ImmutableString>,
|
imports: crate::StaticVec<ImmutableString>,
|
||||||
/// Stack of imported [modules][crate::Module].
|
/// Stack of imported [modules][crate::Module].
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
modules: StaticVec<SharedModule>,
|
modules: crate::StaticVec<crate::SharedModule>,
|
||||||
/// The current stack of loaded [modules][crate::Module] containing script-defined functions.
|
/// The current stack of loaded [modules][crate::Module] containing script-defined functions.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
pub lib: StaticVec<SharedModule>,
|
pub lib: crate::StaticVec<crate::SharedModule>,
|
||||||
/// Source of the current context.
|
/// Source of the current context.
|
||||||
///
|
///
|
||||||
/// No source if the string is empty.
|
/// No source if the string is empty.
|
||||||
@ -84,11 +84,11 @@ impl GlobalRuntimeState {
|
|||||||
pub fn new(engine: &Engine) -> Self {
|
pub fn new(engine: &Engine) -> Self {
|
||||||
Self {
|
Self {
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
imports: StaticVec::new_const(),
|
imports: crate::StaticVec::new_const(),
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
modules: StaticVec::new_const(),
|
modules: crate::StaticVec::new_const(),
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
lib: StaticVec::new_const(),
|
lib: crate::StaticVec::new_const(),
|
||||||
source: None,
|
source: None,
|
||||||
num_operations: 0,
|
num_operations: 0,
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
@ -135,7 +135,7 @@ impl GlobalRuntimeState {
|
|||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_shared_import(&self, index: usize) -> Option<SharedModule> {
|
pub fn get_shared_import(&self, index: usize) -> Option<crate::SharedModule> {
|
||||||
self.modules.get(index).cloned()
|
self.modules.get(index).cloned()
|
||||||
}
|
}
|
||||||
/// Get a mutable reference to the globally-imported [module][crate::Module] at a
|
/// Get a mutable reference to the globally-imported [module][crate::Module] at a
|
||||||
@ -146,7 +146,10 @@ impl GlobalRuntimeState {
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn get_shared_import_mut(&mut self, index: usize) -> Option<&mut SharedModule> {
|
pub(crate) fn get_shared_import_mut(
|
||||||
|
&mut self,
|
||||||
|
index: usize,
|
||||||
|
) -> Option<&mut crate::SharedModule> {
|
||||||
self.modules.get_mut(index)
|
self.modules.get_mut(index)
|
||||||
}
|
}
|
||||||
/// Get the index of a globally-imported [module][crate::Module] by name.
|
/// Get the index of a globally-imported [module][crate::Module] by name.
|
||||||
@ -170,7 +173,7 @@ impl GlobalRuntimeState {
|
|||||||
pub fn push_import(
|
pub fn push_import(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: impl Into<ImmutableString>,
|
name: impl Into<ImmutableString>,
|
||||||
module: impl Into<SharedModule>,
|
module: impl Into<crate::SharedModule>,
|
||||||
) {
|
) {
|
||||||
self.imports.push(name.into());
|
self.imports.push(name.into());
|
||||||
self.modules.push(module.into());
|
self.modules.push(module.into());
|
||||||
@ -203,7 +206,7 @@ impl GlobalRuntimeState {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn iter_imports_raw(
|
pub(crate) fn iter_imports_raw(
|
||||||
&self,
|
&self,
|
||||||
) -> impl Iterator<Item = (&ImmutableString, &SharedModule)> {
|
) -> impl Iterator<Item = (&ImmutableString, &crate::SharedModule)> {
|
||||||
self.imports.iter().zip(self.modules.iter()).rev()
|
self.imports.iter().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.
|
||||||
@ -211,7 +214,9 @@ impl GlobalRuntimeState {
|
|||||||
/// Not available under `no_module`.
|
/// Not available under `no_module`.
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn scan_imports_raw(&self) -> impl Iterator<Item = (&ImmutableString, &SharedModule)> {
|
pub fn scan_imports_raw(
|
||||||
|
&self,
|
||||||
|
) -> impl Iterator<Item = (&ImmutableString, &crate::SharedModule)> {
|
||||||
self.imports.iter().zip(self.modules.iter())
|
self.imports.iter().zip(self.modules.iter())
|
||||||
}
|
}
|
||||||
/// Can the particular function with [`Dynamic`] parameter(s) exist in the stack of
|
/// Can the particular function with [`Dynamic`] parameter(s) exist in the stack of
|
||||||
@ -318,7 +323,7 @@ impl GlobalRuntimeState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
impl<K: Into<ImmutableString>, M: Into<SharedModule>> Extend<(K, M)> for GlobalRuntimeState {
|
impl<K: Into<ImmutableString>, M: Into<crate::SharedModule>> Extend<(K, M)> for GlobalRuntimeState {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn extend<T: IntoIterator<Item = (K, M)>>(&mut self, iter: T) {
|
fn extend<T: IntoIterator<Item = (K, M)>>(&mut self, iter: T) {
|
||||||
for (k, m) in iter {
|
for (k, m) in iter {
|
||||||
|
@ -25,7 +25,7 @@ pub use target::{calc_index, calc_offset_len, Target};
|
|||||||
|
|
||||||
#[cfg(feature = "unchecked")]
|
#[cfg(feature = "unchecked")]
|
||||||
mod unchecked {
|
mod unchecked {
|
||||||
use crate::{eval::GlobalRuntimeState, Dynamic, Engine, Position, RhaiResult, RhaiResultOf};
|
use crate::{eval::GlobalRuntimeState, Dynamic, Engine, Position, RhaiResultOf};
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
|
@ -8,7 +8,7 @@ use crate::ast::{
|
|||||||
use crate::func::{get_builtin_op_assignment_fn, get_hasher};
|
use crate::func::{get_builtin_op_assignment_fn, get_hasher};
|
||||||
use crate::types::dynamic::AccessMode;
|
use crate::types::dynamic::AccessMode;
|
||||||
use crate::types::RestoreOnDrop;
|
use crate::types::RestoreOnDrop;
|
||||||
use crate::{Dynamic, Engine, ImmutableString, RhaiResult, RhaiResultOf, Scope, ERR, INT};
|
use crate::{Dynamic, Engine, RhaiResult, RhaiResultOf, Scope, ERR, INT};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
@ -228,7 +228,7 @@ impl Engine {
|
|||||||
// (returned by a variable resolver, for example)
|
// (returned by a variable resolver, for example)
|
||||||
let is_temp_result = !target.is_ref() && !target.is_shared();
|
let is_temp_result = !target.is_ref() && !target.is_shared();
|
||||||
#[cfg(feature = "no_closure")]
|
#[cfg(feature = "no_closure")]
|
||||||
let is_temp_result = !lhs_ptr.is_ref();
|
let is_temp_result = !target.is_ref();
|
||||||
|
|
||||||
// Cannot assign to temp result from expression
|
// Cannot assign to temp result from expression
|
||||||
if is_temp_result {
|
if is_temp_result {
|
||||||
@ -773,8 +773,8 @@ impl Engine {
|
|||||||
|
|
||||||
let v = self.eval_expr(global, caches, scope, this_ptr, expr)?;
|
let v = self.eval_expr(global, caches, scope, this_ptr, expr)?;
|
||||||
let typ = v.type_name();
|
let typ = v.type_name();
|
||||||
let path = v.try_cast::<ImmutableString>().ok_or_else(|| {
|
let path = v.try_cast::<crate::ImmutableString>().ok_or_else(|| {
|
||||||
self.make_type_mismatch_err::<ImmutableString>(typ, expr.position())
|
self.make_type_mismatch_err::<crate::ImmutableString>(typ, expr.position())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
use crate::ModuleResolver;
|
use crate::ModuleResolver;
|
||||||
|
@ -166,7 +166,7 @@ impl Engine {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
fn resolve_fn<'s>(
|
fn resolve_fn<'s>(
|
||||||
&self,
|
&self,
|
||||||
global: &GlobalRuntimeState,
|
_global: &GlobalRuntimeState,
|
||||||
caches: &'s mut Caches,
|
caches: &'s mut Caches,
|
||||||
local_entry: &'s mut Option<FnResolutionCacheEntry>,
|
local_entry: &'s mut Option<FnResolutionCacheEntry>,
|
||||||
op_token: Option<&Token>,
|
op_token: Option<&Token>,
|
||||||
@ -194,7 +194,7 @@ impl Engine {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
let func = global
|
let func = _global
|
||||||
.lib
|
.lib
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
@ -214,7 +214,7 @@ impl Engine {
|
|||||||
// Scripted functions are not exposed globally
|
// Scripted functions are not exposed globally
|
||||||
func
|
func
|
||||||
} else {
|
} else {
|
||||||
func.or_else(|| global.get_qualified_fn(hash)).or_else(|| {
|
func.or_else(|| _global.get_qualified_fn(hash)).or_else(|| {
|
||||||
self.global_sub_modules
|
self.global_sub_modules
|
||||||
.values()
|
.values()
|
||||||
.find_map(|m| m.get_qualified_fn(hash).map(|f| (f, m.id_raw())))
|
.find_map(|m| m.get_qualified_fn(hash).map(|f| (f, m.id_raw())))
|
||||||
@ -246,14 +246,14 @@ impl Engine {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
let is_dynamic = is_dynamic
|
let is_dynamic = is_dynamic
|
||||||
|| global
|
|| _global
|
||||||
.lib
|
.lib
|
||||||
.iter()
|
.iter()
|
||||||
.any(|m| m.may_contain_dynamic_fn(hash_base));
|
.any(|m| m.may_contain_dynamic_fn(hash_base));
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
let is_dynamic = is_dynamic
|
let is_dynamic = is_dynamic
|
||||||
|| global.may_contain_dynamic_fn(hash_base)
|
|| _global.may_contain_dynamic_fn(hash_base)
|
||||||
|| self
|
|| self
|
||||||
.global_sub_modules
|
.global_sub_modules
|
||||||
.values()
|
.values()
|
||||||
|
@ -7,8 +7,8 @@ use crate::plugin::PluginFunction;
|
|||||||
use crate::tokenizer::{is_valid_function_name, Token, TokenizeState};
|
use crate::tokenizer::{is_valid_function_name, Token, TokenizeState};
|
||||||
use crate::types::dynamic::Variant;
|
use crate::types::dynamic::Variant;
|
||||||
use crate::{
|
use crate::{
|
||||||
calc_fn_hash, Dynamic, Engine, EvalContext, FuncArgs, Module, Position, RhaiResult,
|
calc_fn_hash, Dynamic, Engine, EvalContext, FuncArgs, Position, RhaiResult, RhaiResultOf,
|
||||||
RhaiResultOf, SharedModule, StaticVec, VarDefInfo, ERR,
|
StaticVec, VarDefInfo, ERR,
|
||||||
};
|
};
|
||||||
use std::any::type_name;
|
use std::any::type_name;
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
@ -249,7 +249,7 @@ impl<'a> NativeCallContext<'a> {
|
|||||||
/// Not available under `no_module`.
|
/// Not available under `no_module`.
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn iter_imports(&self) -> impl Iterator<Item = (&str, &Module)> {
|
pub fn iter_imports(&self) -> impl Iterator<Item = (&str, &crate::Module)> {
|
||||||
self.global.iter_imports()
|
self.global.iter_imports()
|
||||||
}
|
}
|
||||||
/// Get an iterator over the current set of modules imported via `import` statements in reverse order.
|
/// Get an iterator over the current set of modules imported via `import` statements in reverse order.
|
||||||
@ -258,7 +258,7 @@ impl<'a> NativeCallContext<'a> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn iter_imports_raw(
|
pub(crate) fn iter_imports_raw(
|
||||||
&self,
|
&self,
|
||||||
) -> impl Iterator<Item = (&crate::ImmutableString, &SharedModule)> {
|
) -> impl Iterator<Item = (&crate::ImmutableString, &crate::SharedModule)> {
|
||||||
self.global.iter_imports_raw()
|
self.global.iter_imports_raw()
|
||||||
}
|
}
|
||||||
/// _(internals)_ The current [`GlobalRuntimeState`], if any.
|
/// _(internals)_ The current [`GlobalRuntimeState`], if any.
|
||||||
@ -277,7 +277,7 @@ impl<'a> NativeCallContext<'a> {
|
|||||||
/// Not available under `no_function`.
|
/// Not available under `no_function`.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn iter_namespaces(&self) -> impl Iterator<Item = &Module> {
|
pub fn iter_namespaces(&self) -> impl Iterator<Item = &crate::Module> {
|
||||||
self.global.lib.iter().map(|m| m.as_ref())
|
self.global.lib.iter().map(|m| m.as_ref())
|
||||||
}
|
}
|
||||||
/// _(internals)_ The current stack of namespaces containing definitions of all script-defined functions.
|
/// _(internals)_ The current stack of namespaces containing definitions of all script-defined functions.
|
||||||
@ -288,7 +288,7 @@ impl<'a> NativeCallContext<'a> {
|
|||||||
#[cfg(feature = "internals")]
|
#[cfg(feature = "internals")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn namespaces(&self) -> &[SharedModule] {
|
pub fn namespaces(&self) -> &[crate::SharedModule] {
|
||||||
&self.global.lib
|
&self.global.lib
|
||||||
}
|
}
|
||||||
/// Call a function inside the call context with the provided arguments.
|
/// Call a function inside the call context with the provided arguments.
|
||||||
|
Loading…
Reference in New Issue
Block a user