Clean up types.

This commit is contained in:
Stephen Chung
2022-11-08 15:01:40 +08:00
parent f4e2901353
commit 6053aa1641
28 changed files with 248 additions and 248 deletions

View File

@@ -11,8 +11,8 @@ use crate::eval::{Caches, FnResolutionCacheEntry, GlobalRuntimeState};
use crate::tokenizer::{is_valid_function_name, Token};
use crate::types::RestoreOnDrop;
use crate::{
calc_fn_hash, calc_fn_hash_full, Dynamic, Engine, FnArgsVec, FnPtr, ImmutableString, Module,
OptimizationLevel, Position, RhaiError, RhaiResult, RhaiResultOf, Scope, Shared, ERR,
calc_fn_hash, calc_fn_hash_full, Dynamic, Engine, FnArgsVec, FnPtr, ImmutableString, SharedModule,
OptimizationLevel, Position, RhaiError, RhaiResult, RhaiResultOf, Scope, ERR,
};
#[cfg(feature = "no_std")]
use hashbrown::hash_map::Entry;
@@ -169,7 +169,7 @@ impl Engine {
_global: &GlobalRuntimeState,
caches: &'s mut Caches,
local_entry: &'s mut Option<FnResolutionCacheEntry>,
lib: &[Shared<Module>],
lib: &[SharedModule],
op_token: Option<&Token>,
hash_base: u64,
args: Option<&mut FnCallArgs>,
@@ -325,7 +325,7 @@ impl Engine {
&self,
global: &mut GlobalRuntimeState,
caches: &mut Caches,
lib: &[Shared<Module>],
lib: &[SharedModule],
level: usize,
name: &str,
op_token: Option<&Token>,
@@ -371,7 +371,7 @@ impl Engine {
}
let args =
&mut *RestoreOnDrop::new_if(swap, &mut args, move |a| backup.restore_first_arg(a));
&mut *RestoreOnDrop::lock_if(swap, &mut args, move |a| backup.restore_first_arg(a));
#[cfg(feature = "debugging")]
if self.debugger.is_some() {
@@ -537,7 +537,7 @@ impl Engine {
&self,
global: &mut GlobalRuntimeState,
caches: &mut Caches,
lib: &[Shared<Module>],
lib: &[SharedModule],
level: usize,
_scope: Option<&mut Scope>,
fn_name: &str,
@@ -585,7 +585,7 @@ impl Engine {
} else {
let hash_script =
calc_fn_hash(None, fn_name.as_str(), num_params as usize);
self.has_script_fn(Some(global), caches, lib, hash_script)
self.has_script_fn(global, caches, lib, hash_script)
}
.into(),
false,
@@ -639,7 +639,7 @@ impl Engine {
};
let orig_source = mem::replace(&mut global.source, source.clone());
let global = &mut *RestoreOnDrop::new(global, move |g| g.source = orig_source);
let global = &mut *RestoreOnDrop::lock(global, move |g| g.source = orig_source);
return if _is_method_call {
// Method call of script function - map first argument to `this`
@@ -668,7 +668,7 @@ impl Engine {
backup.change_first_arg_to_copy(args);
}
let args = &mut *RestoreOnDrop::new_if(swap, &mut args, move |a| {
let args = &mut *RestoreOnDrop::lock_if(swap, &mut args, move |a| {
backup.restore_first_arg(a)
});
@@ -694,7 +694,7 @@ impl Engine {
&self,
global: &mut GlobalRuntimeState,
caches: &mut Caches,
lib: &[Shared<Module>],
lib: &[SharedModule],
level: usize,
scope: &mut Scope,
this_ptr: &mut Option<&mut Dynamic>,
@@ -716,7 +716,7 @@ impl Engine {
matches!(status, crate::eval::DebuggerStatus::FunctionExit(..))
});
#[cfg(feature = "debugging")]
let global = &mut *RestoreOnDrop::new(global, move |g| g.debugger.reset_status(reset));
let global = &mut *RestoreOnDrop::lock(global, move |g| g.debugger.reset_status(reset));
self.eval_expr(global, caches, lib, level, scope, this_ptr, arg_expr)
.map(|r| (r, arg_expr.start_position()))
@@ -728,7 +728,7 @@ impl Engine {
&self,
global: &mut GlobalRuntimeState,
caches: &mut Caches,
lib: &[Shared<Module>],
lib: &[SharedModule],
level: usize,
fn_name: &str,
mut hash: FnCallHashes,
@@ -953,7 +953,7 @@ impl Engine {
&self,
global: &mut GlobalRuntimeState,
caches: &mut Caches,
lib: &[Shared<Module>],
lib: &[SharedModule],
level: usize,
scope: &mut Scope,
this_ptr: &mut Option<&mut Dynamic>,
@@ -1087,7 +1087,7 @@ impl Engine {
false
} else {
let hash_script = calc_fn_hash(None, &fn_name, num_params as usize);
self.has_script_fn(Some(global), caches, lib, hash_script)
self.has_script_fn(global, caches, lib, hash_script)
}
.into());
}
@@ -1244,7 +1244,7 @@ impl Engine {
&self,
global: &mut GlobalRuntimeState,
caches: &mut Caches,
lib: &[Shared<Module>],
lib: &[SharedModule],
level: usize,
scope: &mut Scope,
this_ptr: &mut Option<&mut Dynamic>,
@@ -1378,7 +1378,7 @@ impl Engine {
let new_scope = &mut Scope::new();
let orig_source = mem::replace(&mut global.source, module.id_raw().cloned());
let global = &mut *RestoreOnDrop::new(global, move |g| g.source = orig_source);
let global = &mut *RestoreOnDrop::lock(global, move |g| g.source = orig_source);
self.call_script_fn(
global, caches, lib, level, new_scope, &mut None, fn_def, &mut args, true, pos,
@@ -1426,7 +1426,7 @@ impl Engine {
&self,
global: &mut GlobalRuntimeState,
caches: &mut Caches,
lib: &[Shared<Module>],
lib: &[SharedModule],
level: usize,
scope: &mut Scope,
script: &str,
@@ -1471,7 +1471,7 @@ impl Engine {
&self,
global: &mut GlobalRuntimeState,
caches: &mut Caches,
lib: &[Shared<Module>],
lib: &[SharedModule],
level: usize,
scope: &mut Scope,
this_ptr: &mut Option<&mut Dynamic>,

View File

@@ -8,7 +8,7 @@ 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, StaticVec, VarDefInfo, ERR,
RhaiResultOf, SharedModule, StaticVec, VarDefInfo, ERR,
};
use std::any::type_name;
#[cfg(feature = "no_std")]
@@ -74,7 +74,7 @@ pub struct NativeCallContext<'a> {
/// The current [`GlobalRuntimeState`], if any.
global: Option<&'a GlobalRuntimeState>,
/// The current stack of loaded [modules][Module].
lib: &'a [Shared<Module>],
lib: &'a [SharedModule],
/// [Position] of the function call.
pos: Position,
/// The current nesting level of function calls.
@@ -93,7 +93,7 @@ pub struct NativeCallContextStore {
/// The current [`GlobalRuntimeState`], if any.
pub global: GlobalRuntimeState,
/// The current stack of loaded [modules][Module].
pub lib: StaticVec<Shared<Module>>,
pub lib: StaticVec<SharedModule>,
/// [Position] of the function call.
pub pos: Position,
/// The current nesting level of function calls.
@@ -116,7 +116,7 @@ impl<'a>
&'a str,
Option<&'a str>,
&'a GlobalRuntimeState,
&'a [Shared<Module>],
&'a [SharedModule],
Position,
usize,
)> for NativeCallContext<'a>
@@ -128,7 +128,7 @@ impl<'a>
&'a str,
Option<&'a str>,
&'a GlobalRuntimeState,
&'a [Shared<Module>],
&'a [SharedModule],
Position,
usize,
),
@@ -145,9 +145,9 @@ impl<'a>
}
}
impl<'a> From<(&'a Engine, &'a str, &'a [Shared<Module>])> for NativeCallContext<'a> {
impl<'a> From<(&'a Engine, &'a str, &'a [SharedModule])> for NativeCallContext<'a> {
#[inline(always)]
fn from(value: (&'a Engine, &'a str, &'a [Shared<Module>])) -> Self {
fn from(value: (&'a Engine, &'a str, &'a [SharedModule])) -> Self {
Self {
engine: value.0,
fn_name: value.1,
@@ -169,7 +169,7 @@ impl<'a> NativeCallContext<'a> {
)]
#[inline(always)]
#[must_use]
pub fn new(engine: &'a Engine, fn_name: &'a str, lib: &'a [Shared<Module>]) -> Self {
pub fn new(engine: &'a Engine, fn_name: &'a str, lib: &'a [SharedModule]) -> Self {
Self {
engine,
fn_name,
@@ -193,7 +193,7 @@ impl<'a> NativeCallContext<'a> {
fn_name: &'a str,
source: Option<&'a str>,
global: &'a GlobalRuntimeState,
lib: &'a [Shared<Module>],
lib: &'a [SharedModule],
pos: Position,
level: usize,
) -> Self {
@@ -291,7 +291,7 @@ impl<'a> NativeCallContext<'a> {
#[inline]
pub(crate) fn iter_imports_raw(
&self,
) -> impl Iterator<Item = (&crate::ImmutableString, &Shared<Module>)> {
) -> impl Iterator<Item = (&crate::ImmutableString, &SharedModule)> {
self.global.iter().flat_map(|&g| g.iter_imports_raw())
}
/// _(internals)_ The current [`GlobalRuntimeState`], if any.
@@ -315,7 +315,7 @@ impl<'a> NativeCallContext<'a> {
#[cfg(feature = "internals")]
#[inline(always)]
#[must_use]
pub const fn namespaces(&self) -> &[Shared<Module>] {
pub const fn namespaces(&self) -> &[SharedModule] {
self.lib
}
/// Call a function inside the call context with the provided arguments.

View File

@@ -4,7 +4,7 @@
use super::call::FnCallArgs;
use crate::ast::ScriptFnDef;
use crate::eval::{Caches, GlobalRuntimeState};
use crate::{Dynamic, Engine, Module, Position, RhaiError, RhaiResult, Scope, Shared, ERR};
use crate::{Dynamic, Engine, Position, RhaiError, RhaiResult, Scope, SharedModule, ERR};
use std::mem;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
@@ -26,7 +26,7 @@ impl Engine {
&self,
global: &mut GlobalRuntimeState,
caches: &mut Caches,
lib: &[Shared<Module>],
lib: &[SharedModule],
level: usize,
scope: &mut Scope,
this_ptr: &mut Option<&mut Dynamic>,
@@ -228,9 +228,9 @@ impl Engine {
#[must_use]
pub(crate) fn has_script_fn(
&self,
_global: Option<&GlobalRuntimeState>,
_global: &GlobalRuntimeState,
caches: &mut Caches,
lib: &[Shared<Module>],
lib: &[SharedModule],
hash_script: u64,
) -> bool {
let cache = caches.fn_resolution_cache_mut();
@@ -247,7 +247,7 @@ impl Engine {
#[cfg(not(feature = "no_module"))]
let result = result ||
// Then check imported modules
_global.map_or(false, |m| m.contains_qualified_fn(hash_script))
_global.contains_qualified_fn(hash_script)
// Then check sub-modules
|| self.global_sub_modules.values().any(|m| m.contains_qualified_fn(hash_script));