Share environment when making module from AST.
This commit is contained in:
parent
1de85d749d
commit
0e4743e7c7
@ -150,6 +150,12 @@ impl AST {
|
|||||||
pub(crate) fn statements_mut(&mut self) -> &mut Vec<Stmt> {
|
pub(crate) fn statements_mut(&mut self) -> &mut Vec<Stmt> {
|
||||||
&mut self.0
|
&mut self.0
|
||||||
}
|
}
|
||||||
|
/// Get the internal shared `Module` containing all script-defined functions.
|
||||||
|
#[cfg(not(feature = "internals"))]
|
||||||
|
#[inline(always)]
|
||||||
|
pub(crate) fn shared_lib(&self) -> Shared<Module> {
|
||||||
|
self.1.clone()
|
||||||
|
}
|
||||||
/// Get the internal `Module` containing all script-defined functions.
|
/// Get the internal `Module` containing all script-defined functions.
|
||||||
#[cfg(not(feature = "internals"))]
|
#[cfg(not(feature = "internals"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -1521,14 +1521,12 @@ impl Module {
|
|||||||
// Non-private functions defined become module functions
|
// Non-private functions defined become module functions
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
{
|
{
|
||||||
let ast_lib: Shared<Module> = ast.lib().clone().into();
|
|
||||||
|
|
||||||
ast.iter_functions()
|
ast.iter_functions()
|
||||||
.filter(|(_, access, _, _, _)| !access.is_private())
|
.filter(|(_, access, _, _, _)| !access.is_private())
|
||||||
.for_each(|(_, _, _, _, func)| {
|
.for_each(|(_, _, _, _, func)| {
|
||||||
// Encapsulate AST environment
|
// Encapsulate AST environment
|
||||||
let mut func = func.as_ref().clone();
|
let mut func = func.as_ref().clone();
|
||||||
func.lib = Some(ast_lib.clone());
|
func.lib = Some(ast.shared_lib());
|
||||||
func.mods = func_mods.clone();
|
func.mods = func_mods.clone();
|
||||||
module.set_script_fn(func.into());
|
module.set_script_fn(func.into());
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user