Refine auto_restore syntax.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#![cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
|
||||
|
||||
use super::{Caches, GlobalRuntimeState, Target};
|
||||
use crate::ast::{ASTFlags, Expr, OpAssignment};
|
||||
use crate::ast::{ASTFlags, BinaryExpr, Expr, OpAssignment};
|
||||
use crate::config::hashing::SusLock;
|
||||
use crate::engine::{FN_IDX_GET, FN_IDX_SET};
|
||||
use crate::tokenizer::NO_TOKEN;
|
||||
@@ -346,7 +346,7 @@ impl Engine {
|
||||
) -> RhaiResult {
|
||||
let chain_type = ChainType::from(expr);
|
||||
|
||||
let crate::ast::BinaryExpr { lhs, rhs } = match expr {
|
||||
let BinaryExpr { lhs, rhs } = match expr {
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Expr::Index(x, ..) => &**x,
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
@@ -378,11 +378,9 @@ impl Engine {
|
||||
idx_values.push(rhs.get_literal_value().unwrap())
|
||||
}
|
||||
// All other patterns - evaluate the arguments chain
|
||||
_ => {
|
||||
self.eval_dot_index_chain_arguments(
|
||||
global, caches, scope, this_ptr, expr, rhs, idx_values,
|
||||
)?;
|
||||
}
|
||||
_ => self.eval_dot_index_chain_arguments(
|
||||
global, caches, scope, this_ptr, expr, rhs, idx_values,
|
||||
)?,
|
||||
}
|
||||
|
||||
match lhs {
|
||||
@@ -462,7 +460,7 @@ impl Engine {
|
||||
Expr::Index(x, ..) | Expr::Dot(x, ..)
|
||||
if !parent.options().contains(ASTFlags::BREAK) =>
|
||||
{
|
||||
let crate::ast::BinaryExpr { lhs, rhs, .. } = &**x;
|
||||
let BinaryExpr { lhs, rhs, .. } = &**x;
|
||||
|
||||
let mut _arg_values = FnArgsVec::new_const();
|
||||
|
||||
@@ -690,17 +688,14 @@ impl Engine {
|
||||
let reset =
|
||||
self.run_debugger_with_reset(global, caches, scope, this_ptr, rhs)?;
|
||||
#[cfg(feature = "debugging")]
|
||||
auto_restore!(global if reset.is_some() => move |g| g.debugger_mut().reset_status(reset));
|
||||
auto_restore!(global if Some(reset) => move |g| g.debugger_mut().reset_status(reset));
|
||||
|
||||
let crate::ast::FnCallExpr {
|
||||
name, hashes, args, ..
|
||||
} = &**x;
|
||||
|
||||
// Truncate the index values upon exit
|
||||
auto_restore! {
|
||||
idx_values => truncate;
|
||||
let offset = idx_values.len() - args.len();
|
||||
}
|
||||
auto_restore! { idx_values => truncate; let offset = idx_values.len() - args.len(); }
|
||||
|
||||
let call_args = &mut idx_values[offset..];
|
||||
let arg1_pos = args.get(0).map_or(Position::NONE, Expr::position);
|
||||
@@ -862,17 +857,14 @@ impl Engine {
|
||||
global, caches, scope, this_ptr, _node,
|
||||
)?;
|
||||
#[cfg(feature = "debugging")]
|
||||
auto_restore!(global if reset.is_some() => move |g| g.debugger_mut().reset_status(reset));
|
||||
auto_restore!(global if Some(reset) => move |g| g.debugger_mut().reset_status(reset));
|
||||
|
||||
let crate::ast::FnCallExpr {
|
||||
name, hashes, args, ..
|
||||
} = &**x;
|
||||
|
||||
// Truncate the index values upon exit
|
||||
auto_restore! {
|
||||
idx_values => truncate;
|
||||
let offset = idx_values.len() - args.len();
|
||||
}
|
||||
auto_restore! { idx_values => truncate; let offset = idx_values.len() - args.len(); }
|
||||
|
||||
let call_args = &mut idx_values[offset..];
|
||||
let arg1_pos = args.get(0).map_or(Position::NONE, Expr::position);
|
||||
@@ -983,17 +975,14 @@ impl Engine {
|
||||
global, caches, scope, this_ptr, _node,
|
||||
)?;
|
||||
#[cfg(feature = "debugging")]
|
||||
auto_restore!(global if reset.is_some() => move |g| g.debugger_mut().reset_status(reset));
|
||||
auto_restore!(global if Some(reset) => move |g| g.debugger_mut().reset_status(reset));
|
||||
|
||||
let crate::ast::FnCallExpr {
|
||||
name, hashes, args, ..
|
||||
} = &**f;
|
||||
|
||||
// Truncate the index values upon exit
|
||||
auto_restore! {
|
||||
idx_values => truncate;
|
||||
let offset = idx_values.len() - args.len();
|
||||
}
|
||||
auto_restore! { idx_values => truncate; let offset = idx_values.len() - args.len(); }
|
||||
|
||||
let call_args = &mut idx_values[offset..];
|
||||
let pos1 = args.get(0).map_or(Position::NONE, Expr::position);
|
||||
|
@@ -314,14 +314,12 @@ impl Debugger {
|
||||
None
|
||||
}
|
||||
}
|
||||
/// Override the status of this [`Debugger`] if it is [`Some`] the current status is
|
||||
/// Override the status of this [`Debugger`] if the current status is
|
||||
/// [`CONTINUE`][DebuggerStatus::CONTINUE].
|
||||
#[inline(always)]
|
||||
pub(crate) fn reset_status(&mut self, status: Option<DebuggerStatus>) {
|
||||
pub(crate) fn reset_status(&mut self, status: DebuggerStatus) {
|
||||
if self.status == DebuggerStatus::CONTINUE {
|
||||
if let Some(cmd) = status {
|
||||
self.status = cmd;
|
||||
}
|
||||
self.status = status;
|
||||
}
|
||||
}
|
||||
/// Returns the first break-point triggered by a particular [`AST` Node][ASTNode].
|
||||
|
@@ -234,7 +234,7 @@ impl Engine {
|
||||
#[cfg(feature = "debugging")]
|
||||
let reset = self.run_debugger_with_reset(global, caches, scope, this_ptr, expr)?;
|
||||
#[cfg(feature = "debugging")]
|
||||
auto_restore!(global if reset.is_some() => move |g| g.debugger_mut().reset_status(reset));
|
||||
auto_restore!(global if Some(reset) => move |g| g.debugger_mut().reset_status(reset));
|
||||
|
||||
self.track_operation(global, expr.position())?;
|
||||
|
||||
@@ -265,7 +265,7 @@ impl Engine {
|
||||
#[cfg(feature = "debugging")]
|
||||
let reset = self.run_debugger_with_reset(global, caches, scope, this_ptr, expr)?;
|
||||
#[cfg(feature = "debugging")]
|
||||
auto_restore!(global if reset.is_some() => move |g| g.debugger_mut().reset_status(reset));
|
||||
auto_restore!(global if Some(reset) => move |g| g.debugger_mut().reset_status(reset));
|
||||
|
||||
self.track_operation(global, expr.position())?;
|
||||
|
||||
|
@@ -41,10 +41,7 @@ impl Engine {
|
||||
}
|
||||
|
||||
// Restore scope at end of block if necessary
|
||||
auto_restore! {
|
||||
scope if restore_orig_state => rewind;
|
||||
let orig_scope_len = scope.len();
|
||||
}
|
||||
auto_restore! { scope if restore_orig_state => rewind; let orig_scope_len = scope.len(); }
|
||||
|
||||
// Restore global state at end of block if necessary
|
||||
let orig_always_search_scope = global.always_search_scope;
|
||||
@@ -208,7 +205,7 @@ impl Engine {
|
||||
#[cfg(feature = "debugging")]
|
||||
let reset = self.run_debugger_with_reset(global, caches, scope, this_ptr, stmt)?;
|
||||
#[cfg(feature = "debugging")]
|
||||
auto_restore!(global if reset.is_some() => move |g| g.debugger_mut().reset_status(reset));
|
||||
auto_restore!(global if Some(reset) => move |g| g.debugger_mut().reset_status(reset));
|
||||
|
||||
// Coded this way for better branch prediction.
|
||||
// Popular branches are lifted out of the `match` statement into their own branches.
|
||||
@@ -519,10 +516,8 @@ impl Engine {
|
||||
let iter_func = iter_func.ok_or_else(|| ERR::ErrorFor(expr.start_position()))?;
|
||||
|
||||
// Restore scope at end of statement
|
||||
auto_restore! {
|
||||
scope => rewind;
|
||||
let orig_scope_len = scope.len();
|
||||
}
|
||||
auto_restore! { scope => rewind; let orig_scope_len = scope.len(); }
|
||||
|
||||
// Add the loop variables
|
||||
let counter_index = if counter.is_empty() {
|
||||
usize::MAX
|
||||
@@ -649,10 +644,7 @@ impl Engine {
|
||||
};
|
||||
|
||||
// Restore scope at end of block
|
||||
auto_restore! {
|
||||
scope if !catch_var.is_empty() => rewind;
|
||||
let orig_scope_len = scope.len();
|
||||
}
|
||||
auto_restore! { scope if !catch_var.is_empty() => rewind; let orig_scope_len = scope.len(); }
|
||||
|
||||
if !catch_var.is_empty() {
|
||||
scope.push(catch_var.name.clone(), err_value);
|
||||
|
Reference in New Issue
Block a user