Rename GlobalRuntimeStatemodules -> imports.

This commit is contained in:
Stephen Chung
2022-01-20 08:17:34 +08:00
parent 3d4abeed0e
commit f92894e337
9 changed files with 39 additions and 39 deletions

View File

@@ -56,7 +56,7 @@ impl<'x, 'px, 'pt> EvalContext<'_, 'x, 'px, '_, '_, '_, '_, 'pt> {
#[cfg(not(feature = "no_module"))]
#[inline(always)]
pub fn iter_imports(&self) -> impl Iterator<Item = (&str, &Module)> {
self.global.iter_modules()
self.global.iter_imports()
}
/// _(internals)_ The current [`GlobalRuntimeState`].
/// Exported under the `internals` feature only.

View File

@@ -32,12 +32,12 @@ impl Engine {
};
if let Some(index) = index {
let offset = global.num_imported_modules() - index.get();
Some(global.get_shared_module(offset).unwrap())
let offset = global.num_imports() - index.get();
Some(global.get_shared_import(offset).unwrap())
} else {
global
.find_module(root)
.map(|n| global.get_shared_module(n).unwrap())
.find_import(root)
.map(|n| global.get_shared_import(n).unwrap())
.or_else(|| self.global_sub_modules.get(root).cloned())
}
}

View File

@@ -77,26 +77,26 @@ impl GlobalRuntimeState {
/// Get the length of the stack of globally-imported [modules][Module].
#[inline(always)]
#[must_use]
pub fn num_imported_modules(&self) -> usize {
pub fn num_imports(&self) -> usize {
self.keys.len()
}
/// Get the globally-imported [module][Module] at a particular index.
#[inline(always)]
#[must_use]
pub fn get_shared_module(&self, index: usize) -> Option<Shared<Module>> {
pub fn get_shared_import(&self, index: usize) -> Option<Shared<Module>> {
self.modules.get(index).cloned()
}
/// Get a mutable reference to the globally-imported [module][Module] at a particular index.
#[allow(dead_code)]
#[inline(always)]
#[must_use]
pub(crate) fn get_shared_module_mut(&mut self, index: usize) -> Option<&mut Shared<Module>> {
pub(crate) fn get_shared_import_mut(&mut self, index: usize) -> Option<&mut Shared<Module>> {
self.modules.get_mut(index)
}
/// Get the index of a globally-imported [module][Module] by name.
#[inline]
#[must_use]
pub fn find_module(&self, name: &str) -> Option<usize> {
pub fn find_import(&self, name: &str) -> Option<usize> {
let len = self.keys.len();
self.keys.iter().rev().enumerate().find_map(|(i, key)| {
@@ -109,20 +109,20 @@ impl GlobalRuntimeState {
}
/// Push an imported [module][Module] onto the stack.
#[inline(always)]
pub fn push_module(&mut self, name: impl Into<Identifier>, module: impl Into<Shared<Module>>) {
pub fn push_import(&mut self, name: impl Into<Identifier>, module: impl Into<Shared<Module>>) {
self.keys.push(name.into());
self.modules.push(module.into());
}
/// Truncate the stack of globally-imported [modules][Module] to a particular length.
#[inline(always)]
pub fn truncate_modules(&mut self, size: usize) {
pub fn truncate_imports(&mut self, size: usize) {
self.keys.truncate(size);
self.modules.truncate(size);
}
/// Get an iterator to the stack of globally-imported [modules][Module] in reverse order.
#[allow(dead_code)]
#[inline]
pub fn iter_modules(&self) -> impl Iterator<Item = (&str, &Module)> {
pub fn iter_imports(&self) -> impl Iterator<Item = (&str, &Module)> {
self.keys
.iter()
.rev()
@@ -132,26 +132,26 @@ impl GlobalRuntimeState {
/// Get an iterator to the stack of globally-imported [modules][Module] in reverse order.
#[allow(dead_code)]
#[inline]
pub(crate) fn iter_modules_raw(&self) -> impl Iterator<Item = (&Identifier, &Shared<Module>)> {
pub(crate) fn iter_imports_raw(&self) -> impl Iterator<Item = (&Identifier, &Shared<Module>)> {
self.keys.iter().rev().zip(self.modules.iter().rev())
}
/// Get an iterator to the stack of globally-imported [modules][Module] in forward order.
#[allow(dead_code)]
#[inline]
pub(crate) fn scan_modules_raw(&self) -> impl Iterator<Item = (&Identifier, &Shared<Module>)> {
pub(crate) fn scan_imports_raw(&self) -> impl Iterator<Item = (&Identifier, &Shared<Module>)> {
self.keys.iter().zip(self.modules.iter())
}
/// Does the specified function hash key exist in the stack of globally-imported [modules][Module]?
#[allow(dead_code)]
#[inline]
#[must_use]
pub fn contains_fn(&self, hash: u64) -> bool {
pub fn contains_qualified_fn(&self, hash: u64) -> bool {
self.modules.iter().any(|m| m.contains_qualified_fn(hash))
}
/// Get the specified function via its hash key from the stack of globally-imported [modules][Module].
#[inline]
#[must_use]
pub fn get_fn(&self, hash: u64) -> Option<(&CallableFunction, Option<&str>)> {
pub fn get_qualified_fn(&self, hash: u64) -> Option<(&CallableFunction, Option<&str>)> {
self.modules
.iter()
.rev()

View File

@@ -28,7 +28,7 @@ impl Engine {
let orig_always_search_scope = state.always_search_scope;
let orig_scope_len = scope.len();
let orig_mods_len = global.num_imported_modules();
let orig_mods_len = global.num_imports();
let orig_fn_resolution_caches_len = state.fn_resolution_caches_len();
if restore_orig_state {
@@ -38,7 +38,7 @@ impl Engine {
let mut result = Dynamic::UNIT;
for stmt in statements {
let _mods_len = global.num_imported_modules();
let _mods_len = global.num_imports();
result = self.eval_stmt(
scope,
@@ -56,7 +56,7 @@ impl Engine {
// Get the extra modules - see if any functions are marked global.
// Without global functions, the extra modules never affect function resolution.
if global
.scan_modules_raw()
.scan_imports_raw()
.skip(_mods_len)
.any(|(_, m)| m.contains_indexed_global_functions())
{
@@ -82,7 +82,7 @@ impl Engine {
if restore_orig_state {
scope.rewind(orig_scope_len);
state.scope_level -= 1;
global.truncate_modules(orig_mods_len);
global.truncate_imports(orig_mods_len);
// The impact of new local variables goes away at the end of a block
// because any new variables introduced will go out of scope
@@ -778,9 +778,9 @@ impl Engine {
// Index the module (making a clone copy if necessary) if it is not indexed
let mut module = crate::func::native::shared_take_or_clone(module);
module.build_index();
global.push_module(name, module);
global.push_import(name, module);
} else {
global.push_module(name, module);
global.push_import(name, module);
}
}