Fix builds.

This commit is contained in:
Stephen Chung 2022-11-19 18:57:15 +08:00
parent 62d707ff84
commit 4304da7a47
7 changed files with 39 additions and 34 deletions

View File

@ -1,7 +1,7 @@
//! Evaluation context.
use super::{Caches, GlobalRuntimeState};
use crate::{Dynamic, Engine, Module, Scope};
use crate::{Dynamic, Engine, Scope};
#[cfg(feature = "no_std")]
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).
#[cfg(not(feature = "no_module"))]
#[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()
}
/// 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`.
#[cfg(not(feature = "no_function"))]
#[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())
}
/// _(internals)_ The current set of namespaces containing definitions of all script-defined functions.

View File

@ -4,7 +4,7 @@ use super::{Caches, EvalContext, GlobalRuntimeState, Target};
use crate::ast::{Expr, OpAssignment};
use crate::engine::{KEYWORD_THIS, OP_CONCAT};
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;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
@ -18,7 +18,7 @@ impl Engine {
&self,
global: &GlobalRuntimeState,
namespace: &crate::ast::Namespace,
) -> Option<SharedModule> {
) -> Option<crate::SharedModule> {
assert!(!namespace.is_empty());
let root = namespace.root();

View File

@ -1,6 +1,6 @@
//! Global runtime state.
use crate::{Dynamic, Engine, ImmutableString, SharedModule, StaticVec};
use crate::{Dynamic, Engine, ImmutableString};
use std::fmt;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
@ -25,13 +25,13 @@ pub type GlobalConstants =
pub struct GlobalRuntimeState {
/// Names of imported [modules][crate::Module].
#[cfg(not(feature = "no_module"))]
imports: StaticVec<ImmutableString>,
imports: crate::StaticVec<ImmutableString>,
/// Stack of imported [modules][crate::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.
#[cfg(not(feature = "no_function"))]
pub lib: StaticVec<SharedModule>,
pub lib: crate::StaticVec<crate::SharedModule>,
/// Source of the current context.
///
/// No source if the string is empty.
@ -84,11 +84,11 @@ impl GlobalRuntimeState {
pub fn new(engine: &Engine) -> Self {
Self {
#[cfg(not(feature = "no_module"))]
imports: StaticVec::new_const(),
imports: crate::StaticVec::new_const(),
#[cfg(not(feature = "no_module"))]
modules: StaticVec::new_const(),
modules: crate::StaticVec::new_const(),
#[cfg(not(feature = "no_function"))]
lib: StaticVec::new_const(),
lib: crate::StaticVec::new_const(),
source: None,
num_operations: 0,
#[cfg(not(feature = "no_module"))]
@ -135,7 +135,7 @@ impl GlobalRuntimeState {
#[cfg(not(feature = "no_module"))]
#[inline(always)]
#[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()
}
/// Get a mutable reference to the globally-imported [module][crate::Module] at a
@ -146,7 +146,10 @@ impl GlobalRuntimeState {
#[allow(dead_code)]
#[inline(always)]
#[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)
}
/// Get the index of a globally-imported [module][crate::Module] by name.
@ -170,7 +173,7 @@ impl GlobalRuntimeState {
pub fn push_import(
&mut self,
name: impl Into<ImmutableString>,
module: impl Into<SharedModule>,
module: impl Into<crate::SharedModule>,
) {
self.imports.push(name.into());
self.modules.push(module.into());
@ -203,7 +206,7 @@ impl GlobalRuntimeState {
#[inline]
pub(crate) fn iter_imports_raw(
&self,
) -> impl Iterator<Item = (&ImmutableString, &SharedModule)> {
) -> impl Iterator<Item = (&ImmutableString, &crate::SharedModule)> {
self.imports.iter().zip(self.modules.iter()).rev()
}
/// 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`.
#[cfg(not(feature = "no_module"))]
#[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())
}
/// Can the particular function with [`Dynamic`] parameter(s) exist in the stack of
@ -318,7 +323,7 @@ impl GlobalRuntimeState {
}
#[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]
fn extend<T: IntoIterator<Item = (K, M)>>(&mut self, iter: T) {
for (k, m) in iter {

View File

@ -25,7 +25,7 @@ pub use target::{calc_index, calc_offset_len, Target};
#[cfg(feature = "unchecked")]
mod unchecked {
use crate::{eval::GlobalRuntimeState, Dynamic, Engine, Position, RhaiResult, RhaiResultOf};
use crate::{eval::GlobalRuntimeState, Dynamic, Engine, Position, RhaiResultOf};
use std::borrow::Borrow;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;

View File

@ -8,7 +8,7 @@ use crate::ast::{
use crate::func::{get_builtin_op_assignment_fn, get_hasher};
use crate::types::dynamic::AccessMode;
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};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
@ -228,7 +228,7 @@ impl Engine {
// (returned by a variable resolver, for example)
let is_temp_result = !target.is_ref() && !target.is_shared();
#[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
if is_temp_result {
@ -773,8 +773,8 @@ impl Engine {
let v = self.eval_expr(global, caches, scope, this_ptr, expr)?;
let typ = v.type_name();
let path = v.try_cast::<ImmutableString>().ok_or_else(|| {
self.make_type_mismatch_err::<ImmutableString>(typ, expr.position())
let path = v.try_cast::<crate::ImmutableString>().ok_or_else(|| {
self.make_type_mismatch_err::<crate::ImmutableString>(typ, expr.position())
})?;
use crate::ModuleResolver;

View File

@ -166,7 +166,7 @@ impl Engine {
#[must_use]
fn resolve_fn<'s>(
&self,
global: &GlobalRuntimeState,
_global: &GlobalRuntimeState,
caches: &'s mut Caches,
local_entry: &'s mut Option<FnResolutionCacheEntry>,
op_token: Option<&Token>,
@ -194,7 +194,7 @@ impl Engine {
loop {
#[cfg(not(feature = "no_function"))]
let func = global
let func = _global
.lib
.iter()
.rev()
@ -214,7 +214,7 @@ impl Engine {
// Scripted functions are not exposed globally
func
} 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
.values()
.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"))]
let is_dynamic = is_dynamic
|| global
|| _global
.lib
.iter()
.any(|m| m.may_contain_dynamic_fn(hash_base));
#[cfg(not(feature = "no_module"))]
let is_dynamic = is_dynamic
|| global.may_contain_dynamic_fn(hash_base)
|| _global.may_contain_dynamic_fn(hash_base)
|| self
.global_sub_modules
.values()

View File

@ -7,8 +7,8 @@ use crate::plugin::PluginFunction;
use crate::tokenizer::{is_valid_function_name, Token, TokenizeState};
use crate::types::dynamic::Variant;
use crate::{
calc_fn_hash, Dynamic, Engine, EvalContext, FuncArgs, Module, Position, RhaiResult,
RhaiResultOf, SharedModule, StaticVec, VarDefInfo, ERR,
calc_fn_hash, Dynamic, Engine, EvalContext, FuncArgs, Position, RhaiResult, RhaiResultOf,
StaticVec, VarDefInfo, ERR,
};
use std::any::type_name;
#[cfg(feature = "no_std")]
@ -249,7 +249,7 @@ impl<'a> NativeCallContext<'a> {
/// Not available under `no_module`.
#[cfg(not(feature = "no_module"))]
#[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()
}
/// 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]
pub(crate) fn iter_imports_raw(
&self,
) -> impl Iterator<Item = (&crate::ImmutableString, &SharedModule)> {
) -> impl Iterator<Item = (&crate::ImmutableString, &crate::SharedModule)> {
self.global.iter_imports_raw()
}
/// _(internals)_ The current [`GlobalRuntimeState`], if any.
@ -277,7 +277,7 @@ impl<'a> NativeCallContext<'a> {
/// Not available under `no_function`.
#[cfg(not(feature = "no_function"))]
#[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())
}
/// _(internals)_ The current stack of namespaces containing definitions of all script-defined functions.
@ -288,7 +288,7 @@ impl<'a> NativeCallContext<'a> {
#[cfg(feature = "internals")]
#[inline(always)]
#[must_use]
pub fn namespaces(&self) -> &[SharedModule] {
pub fn namespaces(&self) -> &[crate::SharedModule] {
&self.global.lib
}
/// Call a function inside the call context with the provided arguments.