diff --git a/src/api/call_fn.rs b/src/api/call_fn.rs index bcbcf608..5c48712f 100644 --- a/src/api/call_fn.rs +++ b/src/api/call_fn.rs @@ -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, /// 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(); diff --git a/src/api/deprecated.rs b/src/api/deprecated.rs index 4beaca5b..72cfe1ad 100644 --- a/src/api/deprecated.rs +++ b/src/api/deprecated.rs @@ -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`]. diff --git a/src/api/eval.rs b/src/api/eval.rs index 30880056..7955d1c0 100644 --- a/src/api/eval.rs +++ b/src/api/eval.rs @@ -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) }) diff --git a/src/api/options.rs b/src/api/options.rs index d5aeef90..325dbbcb 100644 --- a/src/api/options.rs +++ b/src/api/options.rs @@ -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? diff --git a/src/api/run.rs b/src/api/run.rs index 8ecf8b2e..4ed9caf5 100644 --- a/src/api/run.rs +++ b/src/api/run.rs @@ -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(()) }) diff --git a/src/eval/chaining.rs b/src/eval/chaining.rs index d2008802..e4baa002 100644 --- a/src/eval/chaining.rs +++ b/src/eval/chaining.rs @@ -392,13 +392,19 @@ impl Engine { self.run_debugger(global, caches, scope, this_ptr, lhs)?; self.track_operation(global, *var_pos)?; - let mut target = self.search_namespace(global, caches, scope, this_ptr, lhs)?; - - let obj_ptr = &mut target; - let mut this = Dynamic::NULL; + let target = &mut self.search_namespace(global, caches, scope, this_ptr, lhs)?; + let mut this_ptr = Dynamic::NULL; self.eval_dot_index_chain_raw( - global, caches, &mut this, lhs, expr, obj_ptr, rhs, idx_values, new_val, + global, + caches, + &mut this_ptr, + lhs, + expr, + target, + rhs, + idx_values, + new_val, ) } // {expr}.??? = ??? or {expr}[???] = ??? diff --git a/src/eval/stmt.rs b/src/eval/stmt.rs index 04681410..99b90f44 100644 --- a/src/eval/stmt.rs +++ b/src/eval/stmt.rs @@ -882,9 +882,9 @@ impl Engine { scope: &mut Scope, statements: &[Stmt], ) -> RhaiResult { - let mut this = Dynamic::NULL; + let mut this_ptr = Dynamic::NULL; - self.eval_stmt_block(global, caches, scope, &mut this, statements, false) + self.eval_stmt_block(global, caches, scope, &mut this_ptr, statements, false) .or_else(|err| match *err { ERR::Return(out, ..) => Ok(out), ERR::LoopBreak(..) => { diff --git a/src/func/call.rs b/src/func/call.rs index a425e845..7a0fafec 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -429,7 +429,7 @@ impl Engine { }; if trigger { let scope = &mut Scope::new(); - let mut this = Dynamic::NULL; + let mut this_ptr = Dynamic::NULL; let node = crate::ast::Stmt::Noop(pos); let node = (&node).into(); let event = match _result { @@ -438,7 +438,7 @@ impl Engine { }; if let Err(err) = - self.run_debugger_raw(global, caches, scope, &mut this, node, event) + self.run_debugger_raw(global, caches, scope, &mut this_ptr, node, event) { _result = Err(err); } @@ -681,9 +681,9 @@ impl Engine { auto_restore!(args = (_args) if swap => move |a| backup.restore_first_arg(a)); - let mut this = Dynamic::NULL; + let mut this_ptr = Dynamic::NULL; - self.call_script_fn(global, caches, scope, &mut this, func, args, true, pos) + self.call_script_fn(global, caches, scope, &mut this_ptr, func, args, true, pos) } .map(|r| (r, false)); } @@ -1248,7 +1248,7 @@ impl Engine { pos: Position, ) -> RhaiResult { let mut arg_values = FnArgsVec::with_capacity(args_expr.len()); - let mut args = FnArgsVec::with_capacity(args_expr.len()); + let args = &mut FnArgsVec::with_capacity(args_expr.len()); let mut first_arg_value = None; if args_expr.is_empty() { @@ -1366,16 +1366,14 @@ impl Engine { match func { #[cfg(not(feature = "no_function"))] Some(f) if f.is_script() => { - let fn_def = f.get_script_fn_def().expect("script-defined function"); - let new_scope = &mut Scope::new(); - let mut this = Dynamic::NULL; + let f = f.get_script_fn_def().expect("script-defined function"); + let scope = &mut Scope::new(); + let mut this_ptr = Dynamic::NULL; let orig_source = mem::replace(&mut global.source, module.id_raw().cloned()); auto_restore!(global => move |g| g.source = orig_source); - self.call_script_fn( - global, caches, new_scope, &mut this, fn_def, &mut args, true, pos, - ) + self.call_script_fn(global, caches, scope, &mut this_ptr, f, args, true, pos) } Some(f) if f.is_plugin_fn() => { @@ -1388,7 +1386,7 @@ impl Engine { if !f.is_pure() && !args.is_empty() && args[0].is_read_only() { Err(ERR::ErrorNonPureMethodCallOnConstant(fn_name.to_string(), pos).into()) } else { - f.call(context, &mut args) + f.call(context, args) .and_then(|r| self.check_data_size(r, pos)) } } @@ -1400,19 +1398,19 @@ impl Engine { } else { None }; - func(context, &mut args).and_then(|r| self.check_data_size(r, pos)) + func(context, args).and_then(|r| self.check_data_size(r, pos)) } Some(f) => unreachable!("unknown function type: {:?}", f), None => { let sig = if namespace.is_empty() { - self.gen_fn_call_signature(fn_name, &args) + self.gen_fn_call_signature(fn_name, args) } else { format!( "{namespace}{}{}", crate::tokenizer::Token::DoubleColon.literal_syntax(), - self.gen_fn_call_signature(fn_name, &args) + self.gen_fn_call_signature(fn_name, args) ) }; diff --git a/src/parser.rs b/src/parser.rs index 12271bbe..3a28f38a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2890,9 +2890,8 @@ impl Engine { will_shadow, }; let caches = &mut Caches::new(); - let mut this = Dynamic::NULL; - - let context = EvalContext::new(self, global, caches, stack, &mut this); + let mut this_ptr = Dynamic::NULL; + let context = EvalContext::new(self, global, caches, stack, &mut this_ptr); match filter(false, info, context) { Ok(true) => (),