simplify access to globals
This commit is contained in:
parent
704b4d50b8
commit
9fffaeb876
|
@ -11,6 +11,7 @@ use hashmap_core::HashMap;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX};
|
use common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX};
|
||||||
|
use core::cell::Ref;
|
||||||
use func::{FuncBody, FuncInstance, FuncRef};
|
use func::{FuncBody, FuncInstance, FuncRef};
|
||||||
use global::{GlobalInstance, GlobalRef};
|
use global::{GlobalInstance, GlobalRef};
|
||||||
use host::Externals;
|
use host::Externals;
|
||||||
|
@ -183,10 +184,7 @@ impl ModuleInstance {
|
||||||
self.tables.borrow_mut().get(idx as usize).cloned()
|
self.tables.borrow_mut().get(idx as usize).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get global by index. Index can be obtained by calling [globals].
|
pub(crate) fn global_by_index(&self, idx: u32) -> Option<GlobalRef> {
|
||||||
///
|
|
||||||
/// [globals]: [#method.globals]
|
|
||||||
pub fn global_by_index(&self, idx: u32) -> Option<GlobalRef> {
|
|
||||||
self.globals.borrow_mut().get(idx as usize).cloned()
|
self.globals.borrow_mut().get(idx as usize).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,15 +216,10 @@ impl ModuleInstance {
|
||||||
self.globals.borrow_mut().push(global)
|
self.globals.borrow_mut().push(global)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enumerates over globals, index can be used as an argument to [global_by_index].
|
/// Access all globals. This is a non-standard API so it's unlikely to be
|
||||||
///
|
/// portable to other engines.
|
||||||
/// [global_by_index]: #method.global_by_index
|
pub fn globals<'a>(&self) -> Ref<Vec<GlobalRef>> {
|
||||||
pub fn globals(&self) -> impl Iterator<Item = (u32, GlobalRef)> {
|
self.globals.borrow()
|
||||||
let globals = self.globals.borrow().clone();
|
|
||||||
globals
|
|
||||||
.into_iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(idx, global)| (idx as u32, global))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_export<N: Into<String>>(&self, name: N, extern_val: ExternVal) {
|
fn insert_export<N: Into<String>>(&self, name: N, extern_val: ExternVal) {
|
||||||
|
|
Loading…
Reference in New Issue