Minor refactor.

This commit is contained in:
Stephen Chung 2022-06-09 08:41:51 +08:00
parent e5f6b28abd
commit 285bf23dfa
3 changed files with 13 additions and 22 deletions

View File

@ -162,7 +162,7 @@ impl Engine {
) -> RhaiResult { ) -> RhaiResult {
let mut arg_values = arg_values; let mut arg_values = arg_values;
self.call_fn_internal( self._call_fn(
scope, scope,
&mut GlobalRuntimeState::new(self), &mut GlobalRuntimeState::new(self),
&mut Caches::new(), &mut Caches::new(),
@ -215,7 +215,7 @@ impl Engine {
this_ptr: Option<&mut Dynamic>, this_ptr: Option<&mut Dynamic>,
arg_values: &mut [Dynamic], arg_values: &mut [Dynamic],
) -> RhaiResult { ) -> RhaiResult {
self.call_fn_internal( self._call_fn(
scope, scope,
global, global,
caches, caches,
@ -228,7 +228,7 @@ impl Engine {
) )
} }
/// Call a script function defined in an [`AST`] with multiple [`Dynamic`] arguments. /// Call a script function defined in an [`AST`] with multiple [`Dynamic`] arguments.
fn call_fn_internal( fn _call_fn(
&self, &self,
scope: &mut Scope, scope: &mut Scope,
global: &mut GlobalRuntimeState, global: &mut GlobalRuntimeState,

View File

@ -809,30 +809,21 @@ impl AST {
/// Return `false` from the callback to terminate the walk. /// Return `false` from the callback to terminate the walk.
#[cfg(not(feature = "internals"))] #[cfg(not(feature = "internals"))]
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
#[inline] #[inline(always)]
pub(crate) fn walk(&self, on_node: &mut impl FnMut(&[ASTNode]) -> bool) -> bool { pub(crate) fn walk(&self, on_node: &mut impl FnMut(&[ASTNode]) -> bool) -> bool {
let path = &mut Vec::new(); self.walk_raw(on_node)
for stmt in self.statements() {
if !stmt.walk(path, on_node) {
return false;
}
}
#[cfg(not(feature = "no_function"))]
for stmt in self.iter_fn_def().flat_map(|f| f.body.iter()) {
if !stmt.walk(path, on_node) {
return false;
}
}
true
} }
/// _(internals)_ Recursively walk the [`AST`], including function bodies (if any). /// _(internals)_ Recursively walk the [`AST`], including function bodies (if any).
/// Return `false` from the callback to terminate the walk. /// Return `false` from the callback to terminate the walk.
/// Exported under the `internals` feature only. /// Exported under the `internals` feature only.
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
#[inline] #[inline(always)]
pub fn walk(&self, on_node: &mut impl FnMut(&[ASTNode]) -> bool) -> bool { pub fn walk(&self, on_node: &mut impl FnMut(&[ASTNode]) -> bool) -> bool {
self._walk(on_node)
}
/// Recursively walk the [`AST`], including function bodies (if any).
/// Return `false` from the callback to terminate the walk.
fn _walk(&self, on_node: &mut impl FnMut(&[ASTNode]) -> bool) -> bool {
let path = &mut Vec::new(); let path = &mut Vec::new();
for stmt in self.statements() { for stmt in self.statements() {

View File

@ -57,7 +57,7 @@ pub struct ParseState<'e> {
pub block_stack_len: usize, pub block_stack_len: usize,
/// Tracks a list of external variables (variables that are not explicitly declared in the scope). /// Tracks a list of external variables (variables that are not explicitly declared in the scope).
#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "no_closure"))]
pub external_vars: Vec<crate::ast::Ident>, pub external_vars: crate::FnArgsVec<crate::ast::Ident>,
/// An indicator that disables variable capturing into externals one single time /// An indicator that disables variable capturing into externals one single time
/// up until the nearest consumed Identifier token. /// up until the nearest consumed Identifier token.
/// If set to false the next call to [`access_var`][ParseState::access_var] will not capture the variable. /// If set to false the next call to [`access_var`][ParseState::access_var] will not capture the variable.
@ -80,7 +80,7 @@ impl<'e> ParseState<'e> {
Self { Self {
tokenizer_control, tokenizer_control,
#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "no_closure"))]
external_vars: Vec::new(), external_vars: crate::FnArgsVec::new_const(),
#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "no_closure"))]
allow_capture: true, allow_capture: true,
interned_strings: StringsInterner::new(), interned_strings: StringsInterner::new(),