Minor cleanup.

This commit is contained in:
Stephen Chung
2022-12-09 20:42:55 +08:00
parent 30ff208104
commit f15a9a7c9c
9 changed files with 41 additions and 38 deletions

View File

@@ -18,9 +18,9 @@ use std::{
#[non_exhaustive]
#[must_use]
pub struct CallFnOptions<'t> {
/// A value for binding to the `this` pointer (if any).
/// A value for binding to the `this` pointer (if any). Default [`None`].
pub this_ptr: Option<&'t mut Dynamic>,
/// The custom state of this evaluation run (if any), overrides [`Engine::default_tag`].
/// The custom state of this evaluation run (if any), overrides [`Engine::default_tag`]. Default [`None`].
pub tag: Option<Dynamic>,
/// Evaluate the [`AST`] to load necessary modules before calling the function? Default `true`.
pub eval_ast: bool,
@@ -172,13 +172,13 @@ impl Engine {
args.parse(&mut arg_values);
self._call_fn(
options,
scope,
&mut GlobalRuntimeState::new(self),
&mut Caches::new(),
ast,
name.as_ref(),
arg_values.as_mut(),
options,
)
.and_then(|result| {
// Bail out early if the return type needs no cast
@@ -207,13 +207,13 @@ impl Engine {
#[inline(always)]
pub(crate) fn _call_fn(
&self,
options: CallFnOptions,
scope: &mut Scope,
global: &mut GlobalRuntimeState,
caches: &mut Caches,
ast: &AST,
name: &str,
arg_values: &mut [Dynamic],
options: CallFnOptions,
) -> RhaiResult {
let statements = ast.statements();

View File

@@ -167,13 +167,13 @@ impl Engine {
};
self._call_fn(
options,
scope,
&mut crate::eval::GlobalRuntimeState::new(self),
&mut crate::eval::Caches::new(),
ast,
name.as_ref(),
arg_values.as_mut(),
options,
)
}
/// Register a custom fallible function with the [`Engine`].

View File

@@ -250,9 +250,9 @@ impl Engine {
#[cfg(feature = "debugging")]
if self.is_debugger_registered() {
global.debugger_mut().status = crate::eval::DebuggerStatus::Terminate;
let mut this = Dynamic::NULL;
let mut this_ptr = Dynamic::NULL;
let node = &crate::ast::Stmt::Noop(Position::NONE);
self.run_debugger(global, caches, scope, &mut this, node)?;
self.run_debugger(global, caches, scope, &mut this_ptr, node)?;
}
Ok(r)
})

View File

@@ -22,7 +22,7 @@ bitflags! {
/// Is looping allowed?
const LOOPING = 0b_0000_0010_0000;
/// Is variables shadowing allowed?
const SHADOW = 0b_0000_0100_0000;
const SHADOWING = 0b_0000_0100_0000;
/// Strict variables mode?
const STRICT_VAR = 0b_0000_1000_0000;
/// Raise error if an object map property does not exist?
@@ -43,7 +43,7 @@ impl LangOptions {
| Self::SWITCH_EXPR
| Self::STMT_EXPR
| Self::LOOPING
| Self::SHADOW
| Self::SHADOWING
| Self::FAST_OPS
| {
#[cfg(not(feature = "no_function"))]
@@ -148,12 +148,12 @@ impl Engine {
#[inline(always)]
#[must_use]
pub const fn allow_shadowing(&self) -> bool {
self.options.contains(LangOptions::SHADOW)
self.options.contains(LangOptions::SHADOWING)
}
/// Set whether variables shadowing is allowed.
#[inline(always)]
pub fn set_allow_shadowing(&mut self, enable: bool) -> &mut Self {
self.options.set(LangOptions::SHADOW, enable);
self.options.set(LangOptions::SHADOWING, enable);
self
}
/// Is strict variables mode enabled?

View File

@@ -131,9 +131,9 @@ impl Engine {
#[cfg(feature = "debugging")]
if self.is_debugger_registered() {
global.debugger_mut().status = crate::eval::DebuggerStatus::Terminate;
let mut this = crate::Dynamic::NULL;
let mut this_ptr = crate::Dynamic::NULL;
let node = &crate::ast::Stmt::Noop(crate::Position::NONE);
self.run_debugger(global, caches, scope, &mut this, node)?;
self.run_debugger(global, caches, scope, &mut this_ptr, node)?;
}
Ok(())
})