Simplify using ..
This commit is contained in:
@@ -25,9 +25,9 @@ impl From<&Expr> for ChainType {
|
||||
fn from(expr: &Expr) -> Self {
|
||||
match expr {
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Expr::Index(_, _, _) => Self::Indexing,
|
||||
Expr::Index(..) => Self::Indexing,
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Expr::Dot(_, _, _) => Self::Dotting,
|
||||
Expr::Dot(..) => Self::Dotting,
|
||||
expr => unreachable!("Expr::Index or Expr::Dot expected but gets {:?}", expr),
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ impl ChainArgument {
|
||||
#[must_use]
|
||||
pub fn into_index_value(self) -> Option<Dynamic> {
|
||||
match self {
|
||||
Self::IndexValue(value, _) => Some(value),
|
||||
Self::IndexValue(value, ..) => Some(value),
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
_ => None,
|
||||
}
|
||||
@@ -89,9 +89,9 @@ impl ChainArgument {
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
ChainArgument::Property(pos) => *pos,
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
ChainArgument::MethodCallArgs(_, pos) => *pos,
|
||||
ChainArgument::MethodCallArgs(.., pos) => *pos,
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
ChainArgument::IndexValue(_, pos) => *pos,
|
||||
ChainArgument::IndexValue(.., pos) => *pos,
|
||||
}
|
||||
}
|
||||
/// Create n [`MethodCallArgs`][ChainArgument::MethodCallArgs].
|
||||
@@ -193,7 +193,7 @@ impl Engine {
|
||||
true, root_pos, level,
|
||||
) {
|
||||
// Just ignore if there is no index setter
|
||||
if !matches!(*err, ERR::ErrorFunctionNotFound(_, _)) {
|
||||
if !matches!(*err, ERR::ErrorFunctionNotFound(..)) {
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
@@ -225,9 +225,7 @@ impl Engine {
|
||||
}
|
||||
// Can't index - try to call an index setter
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Err(err) if matches!(*err, ERR::ErrorIndexingType(_, _)) => {
|
||||
Some(new_val)
|
||||
}
|
||||
Err(err) if matches!(*err, ERR::ErrorIndexingType(..)) => Some(new_val),
|
||||
// Any other error
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
@@ -283,11 +281,11 @@ impl Engine {
|
||||
result
|
||||
}
|
||||
// xxx.fn_name(...) = ???
|
||||
Expr::FnCall(_, _) if new_val.is_some() => {
|
||||
Expr::FnCall(..) if new_val.is_some() => {
|
||||
unreachable!("method call cannot be assigned to")
|
||||
}
|
||||
// xxx.module::fn_name(...) - syntax error
|
||||
Expr::FnCall(_, _) => {
|
||||
Expr::FnCall(..) => {
|
||||
unreachable!("function call in dot chain should not be namespace-qualified")
|
||||
}
|
||||
// {xxx:map}.id op= ???
|
||||
@@ -333,14 +331,14 @@ impl Engine {
|
||||
if op_info.is_some() {
|
||||
let hash = crate::ast::FnCallHashes::from_native(*hash_get);
|
||||
let args = &mut [target.as_mut()];
|
||||
let (mut orig_val, _) = self
|
||||
let (mut orig_val, ..) = self
|
||||
.exec_fn_call(
|
||||
None, global, state, lib, getter, hash, args, is_ref_mut, true,
|
||||
*pos, level,
|
||||
)
|
||||
.or_else(|err| match *err {
|
||||
// Try an indexer if property does not exist
|
||||
ERR::ErrorDotExpr(_, _) => {
|
||||
ERR::ErrorDotExpr(..) => {
|
||||
let prop = name.into();
|
||||
self.get_indexed_mut(
|
||||
global, state, lib, target, prop, *pos, false, true,
|
||||
@@ -349,7 +347,7 @@ impl Engine {
|
||||
.map(|v| (v.take_or_clone(), false))
|
||||
.map_err(
|
||||
|idx_err| match *idx_err {
|
||||
ERR::ErrorIndexingType(_, _) => err,
|
||||
ERR::ErrorIndexingType(..) => err,
|
||||
_ => idx_err,
|
||||
},
|
||||
)
|
||||
@@ -381,7 +379,7 @@ impl Engine {
|
||||
)
|
||||
.or_else(|err| match *err {
|
||||
// Try an indexer if property does not exist
|
||||
ERR::ErrorDotExpr(_, _) => {
|
||||
ERR::ErrorDotExpr(..) => {
|
||||
let args = &mut [target, &mut name.into(), &mut new_val];
|
||||
let fn_name = crate::engine::FN_IDX_SET;
|
||||
let hash_set =
|
||||
@@ -394,7 +392,7 @@ impl Engine {
|
||||
)
|
||||
.map_err(
|
||||
|idx_err| match *idx_err {
|
||||
ERR::ErrorIndexingType(_, _) => err,
|
||||
ERR::ErrorIndexingType(..) => err,
|
||||
_ => idx_err,
|
||||
},
|
||||
)
|
||||
@@ -417,7 +415,7 @@ impl Engine {
|
||||
.map_or_else(
|
||||
|err| match *err {
|
||||
// Try an indexer if property does not exist
|
||||
ERR::ErrorDotExpr(_, _) => {
|
||||
ERR::ErrorDotExpr(..) => {
|
||||
let prop = name.into();
|
||||
self.get_indexed_mut(
|
||||
global, state, lib, target, prop, *pos, false, true, level,
|
||||
@@ -425,7 +423,7 @@ impl Engine {
|
||||
.map(|v| (v.take_or_clone(), false))
|
||||
.map_err(|idx_err| {
|
||||
match *idx_err {
|
||||
ERR::ErrorIndexingType(_, _) => err,
|
||||
ERR::ErrorIndexingType(..) => err,
|
||||
_ => idx_err,
|
||||
}
|
||||
})
|
||||
@@ -433,7 +431,7 @@ impl Engine {
|
||||
_ => Err(err),
|
||||
},
|
||||
// Assume getters are always pure
|
||||
|(v, _)| Ok((v, false)),
|
||||
|(v, ..)| Ok((v, false)),
|
||||
)
|
||||
}
|
||||
// {xxx:map}.sub_lhs[expr] | {xxx:map}.sub_lhs.expr
|
||||
@@ -475,7 +473,7 @@ impl Engine {
|
||||
result?.0.into()
|
||||
}
|
||||
// {xxx:map}.module::fn_name(...) - syntax error
|
||||
Expr::FnCall(_, _) => unreachable!(
|
||||
Expr::FnCall(..) => unreachable!(
|
||||
"function call in dot chain should not be namespace-qualified"
|
||||
),
|
||||
// Others - syntax error
|
||||
@@ -509,14 +507,14 @@ impl Engine {
|
||||
let args = &mut arg_values[..1];
|
||||
|
||||
// Assume getters are always pure
|
||||
let (mut val, _) = self
|
||||
let (mut val, ..) = self
|
||||
.exec_fn_call(
|
||||
None, global, state, lib, getter, hash_get, args,
|
||||
is_ref_mut, true, pos, level,
|
||||
)
|
||||
.or_else(|err| match *err {
|
||||
// Try an indexer if property does not exist
|
||||
ERR::ErrorDotExpr(_, _) => {
|
||||
ERR::ErrorDotExpr(..) => {
|
||||
let prop = name.into();
|
||||
self.get_indexed_mut(
|
||||
global, state, lib, target, prop, pos, false, true,
|
||||
@@ -525,7 +523,7 @@ impl Engine {
|
||||
.map(|v| (v.take_or_clone(), false))
|
||||
.map_err(
|
||||
|idx_err| match *idx_err {
|
||||
ERR::ErrorIndexingType(_, _) => err,
|
||||
ERR::ErrorIndexingType(..) => err,
|
||||
_ => idx_err,
|
||||
},
|
||||
)
|
||||
@@ -565,7 +563,7 @@ impl Engine {
|
||||
.or_else(
|
||||
|err| match *err {
|
||||
// Try an indexer if property does not exist
|
||||
ERR::ErrorDotExpr(_, _) => {
|
||||
ERR::ErrorDotExpr(..) => {
|
||||
let args =
|
||||
&mut [target.as_mut(), &mut name.into(), val];
|
||||
let fn_name = crate::engine::FN_IDX_SET;
|
||||
@@ -578,7 +576,7 @@ impl Engine {
|
||||
args, is_ref_mut, true, pos, level,
|
||||
)
|
||||
.or_else(|idx_err| match *idx_err {
|
||||
ERR::ErrorIndexingType(_, _) => {
|
||||
ERR::ErrorIndexingType(..) => {
|
||||
// If there is no setter, no need to feed it back because
|
||||
// the property is read-only
|
||||
Ok((Dynamic::UNIT, false))
|
||||
@@ -621,7 +619,7 @@ impl Engine {
|
||||
.map_err(|err| err.fill_position(pos))
|
||||
}
|
||||
// xxx.module::fn_name(...) - syntax error
|
||||
Expr::FnCall(_, _) => unreachable!(
|
||||
Expr::FnCall(..) => unreachable!(
|
||||
"function call in dot chain should not be namespace-qualified"
|
||||
),
|
||||
// Others - syntax error
|
||||
@@ -665,14 +663,14 @@ impl Engine {
|
||||
|
||||
match lhs {
|
||||
// id.??? or id[???]
|
||||
Expr::Variable(_, var_pos, x) => {
|
||||
Expr::Variable(.., var_pos, x) => {
|
||||
#[cfg(feature = "debugging")]
|
||||
self.run_debugger(scope, global, state, lib, this_ptr, lhs, level)?;
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
self.inc_operations(&mut global.num_operations, *var_pos)?;
|
||||
|
||||
let (mut target, _) =
|
||||
let (mut target, ..) =
|
||||
self.search_namespace(scope, global, state, lib, this_ptr, lhs, level)?;
|
||||
|
||||
let obj_ptr = &mut target;
|
||||
@@ -682,7 +680,7 @@ impl Engine {
|
||||
global, state, lib, &mut None, obj_ptr, root, expr, rhs, term, idx_values,
|
||||
chain_type, level, new_val,
|
||||
)
|
||||
.map(|(v, _)| v)
|
||||
.map(|(v, ..)| v)
|
||||
.map_err(|err| err.fill_position(op_pos))
|
||||
}
|
||||
// {expr}.??? = ??? or {expr}[???] = ???
|
||||
@@ -696,7 +694,7 @@ impl Engine {
|
||||
global, state, lib, this_ptr, obj_ptr, root, expr, rhs, term, idx_values,
|
||||
chain_type, level, new_val,
|
||||
)
|
||||
.map(|(v, _)| if is_assignment { Dynamic::UNIT } else { v })
|
||||
.map(|(v, ..)| if is_assignment { Dynamic::UNIT } else { v })
|
||||
.map_err(|err| err.fill_position(op_pos))
|
||||
}
|
||||
}
|
||||
@@ -726,7 +724,7 @@ impl Engine {
|
||||
|
||||
match expr {
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Expr::FnCall(x, _) if _parent_chain_type == ChainType::Dotting && !x.is_qualified() => {
|
||||
Expr::FnCall(x, ..) if _parent_chain_type == ChainType::Dotting && !x.is_qualified() => {
|
||||
let crate::ast::FnCallExpr {
|
||||
args, constants, ..
|
||||
} = x.as_ref();
|
||||
@@ -748,29 +746,29 @@ impl Engine {
|
||||
idx_values.push(super::ChainArgument::from_fn_call_args(values, pos));
|
||||
}
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Expr::FnCall(_, _) if _parent_chain_type == ChainType::Dotting => {
|
||||
Expr::FnCall(..) if _parent_chain_type == ChainType::Dotting => {
|
||||
unreachable!("function call in dot chain should not be namespace-qualified")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Expr::Property(_, pos) if _parent_chain_type == ChainType::Dotting => {
|
||||
Expr::Property(.., pos) if _parent_chain_type == ChainType::Dotting => {
|
||||
idx_values.push(super::ChainArgument::Property(*pos))
|
||||
}
|
||||
Expr::Property(_, _) => unreachable!("unexpected Expr::Property for indexing"),
|
||||
Expr::Property(..) => unreachable!("unexpected Expr::Property for indexing"),
|
||||
|
||||
Expr::Index(x, term, _) | Expr::Dot(x, term, _) if !terminate_chaining => {
|
||||
Expr::Index(x, term, ..) | Expr::Dot(x, term, ..) if !terminate_chaining => {
|
||||
let crate::ast::BinaryExpr { lhs, rhs, .. } = x.as_ref();
|
||||
|
||||
// Evaluate in left-to-right order
|
||||
let lhs_arg_val = match lhs {
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Expr::Property(_, pos) if _parent_chain_type == ChainType::Dotting => {
|
||||
Expr::Property(.., pos) if _parent_chain_type == ChainType::Dotting => {
|
||||
super::ChainArgument::Property(*pos)
|
||||
}
|
||||
Expr::Property(_, _) => unreachable!("unexpected Expr::Property for indexing"),
|
||||
Expr::Property(..) => unreachable!("unexpected Expr::Property for indexing"),
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Expr::FnCall(x, _)
|
||||
Expr::FnCall(x, ..)
|
||||
if _parent_chain_type == ChainType::Dotting && !x.is_qualified() =>
|
||||
{
|
||||
let crate::ast::FnCallExpr {
|
||||
@@ -793,7 +791,7 @@ impl Engine {
|
||||
super::ChainArgument::from_fn_call_args(values, pos)
|
||||
}
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Expr::FnCall(_, _) if _parent_chain_type == ChainType::Dotting => {
|
||||
Expr::FnCall(..) if _parent_chain_type == ChainType::Dotting => {
|
||||
unreachable!("function call in dot chain should not be namespace-qualified")
|
||||
}
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
@@ -862,7 +860,7 @@ impl Engine {
|
||||
|
||||
match target {
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Dynamic(Union::Array(arr, _, _)) => {
|
||||
Dynamic(Union::Array(arr, ..)) => {
|
||||
// val_array[idx]
|
||||
let index = idx
|
||||
.as_int()
|
||||
@@ -876,7 +874,7 @@ impl Engine {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Dynamic(Union::Blob(arr, _, _)) => {
|
||||
Dynamic(Union::Blob(arr, ..)) => {
|
||||
// val_blob[idx]
|
||||
let index = idx
|
||||
.as_int()
|
||||
@@ -896,7 +894,7 @@ impl Engine {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Dynamic(Union::Map(map, _, _)) => {
|
||||
Dynamic(Union::Map(map, ..)) => {
|
||||
// val_map[idx]
|
||||
let index = idx.read_lock::<crate::ImmutableString>().ok_or_else(|| {
|
||||
self.make_type_mismatch_err::<crate::ImmutableString>(idx.type_name(), pos)
|
||||
@@ -913,7 +911,7 @@ impl Engine {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Dynamic(Union::Int(value, _, _))
|
||||
Dynamic(Union::Int(value, ..))
|
||||
if idx.is::<crate::ExclusiveRange>() || idx.is::<crate::InclusiveRange>() =>
|
||||
{
|
||||
// val_int[range]
|
||||
@@ -984,7 +982,7 @@ impl Engine {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Dynamic(Union::Int(value, _, _)) => {
|
||||
Dynamic(Union::Int(value, ..)) => {
|
||||
// val_int[idx]
|
||||
let index = idx
|
||||
.as_int()
|
||||
@@ -1006,7 +1004,7 @@ impl Engine {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Dynamic(Union::Str(s, _, _)) => {
|
||||
Dynamic(Union::Str(s, ..)) => {
|
||||
// val_string[idx]
|
||||
let index = idx
|
||||
.as_int()
|
||||
@@ -1052,7 +1050,7 @@ impl Engine {
|
||||
self.exec_fn_call(
|
||||
None, global, state, lib, fn_name, hash_get, args, true, true, pos, level,
|
||||
)
|
||||
.map(|(v, _)| v.into())
|
||||
.map(|(v, ..)| v.into())
|
||||
}
|
||||
|
||||
_ => Err(ERR::ErrorIndexingType(
|
||||
|
@@ -21,51 +21,51 @@ impl Engine {
|
||||
|
||||
match value.0 {
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Union::Array(ref arr, _, _) => {
|
||||
Union::Array(ref arr, ..) => {
|
||||
arr.iter()
|
||||
.fold((0, 0, 0), |(arrays, maps, strings), value| match value.0 {
|
||||
Union::Array(_, _, _) => {
|
||||
Union::Array(..) => {
|
||||
let (a, m, s) = Self::calc_data_sizes(value, false);
|
||||
(arrays + a + 1, maps + m, strings + s)
|
||||
}
|
||||
Union::Blob(ref a, _, _) => (arrays + 1 + a.len(), maps, strings),
|
||||
Union::Blob(ref a, ..) => (arrays + 1 + a.len(), maps, strings),
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Union::Map(_, _, _) => {
|
||||
Union::Map(..) => {
|
||||
let (a, m, s) = Self::calc_data_sizes(value, false);
|
||||
(arrays + a + 1, maps + m, strings + s)
|
||||
}
|
||||
Union::Str(ref s, _, _) => (arrays + 1, maps, strings + s.len()),
|
||||
Union::Str(ref s, ..) => (arrays + 1, maps, strings + s.len()),
|
||||
_ => (arrays + 1, maps, strings),
|
||||
})
|
||||
}
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Union::Blob(ref arr, _, _) => (arr.len(), 0, 0),
|
||||
Union::Blob(ref arr, ..) => (arr.len(), 0, 0),
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Union::Map(ref map, _, _) => {
|
||||
Union::Map(ref map, ..) => {
|
||||
map.values()
|
||||
.fold((0, 0, 0), |(arrays, maps, strings), value| match value.0 {
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Union::Array(_, _, _) => {
|
||||
Union::Array(..) => {
|
||||
let (a, m, s) = Self::calc_data_sizes(value, false);
|
||||
(arrays + a, maps + m + 1, strings + s)
|
||||
}
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Union::Blob(ref a, _, _) => (arrays + a.len(), maps, strings),
|
||||
Union::Map(_, _, _) => {
|
||||
Union::Blob(ref a, ..) => (arrays + a.len(), maps, strings),
|
||||
Union::Map(..) => {
|
||||
let (a, m, s) = Self::calc_data_sizes(value, false);
|
||||
(arrays + a, maps + m + 1, strings + s)
|
||||
}
|
||||
Union::Str(ref s, _, _) => (arrays, maps + 1, strings + s.len()),
|
||||
Union::Str(ref s, ..) => (arrays, maps + 1, strings + s.len()),
|
||||
_ => (arrays, maps + 1, strings),
|
||||
})
|
||||
}
|
||||
Union::Str(ref s, _, _) => (0, 0, s.len()),
|
||||
Union::Str(ref s, ..) => (0, 0, s.len()),
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(_, _, _) if _top => {
|
||||
Union::Shared(..) if _top => {
|
||||
Self::calc_data_sizes(&*value.read_lock::<Dynamic>().unwrap(), true)
|
||||
}
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(_, _, _) => {
|
||||
Union::Shared(..) => {
|
||||
unreachable!("shared values discovered within data: {}", value)
|
||||
}
|
||||
_ => (0, 0, 0),
|
||||
|
@@ -271,7 +271,7 @@ impl Debugger {
|
||||
} else {
|
||||
DebuggerStatus::CONTINUE
|
||||
},
|
||||
state: if let Some((ref init, _)) = engine.debugger {
|
||||
state: if let Some((ref init, ..)) = engine.debugger {
|
||||
init()
|
||||
} else {
|
||||
Dynamic::UNIT
|
||||
@@ -348,8 +348,8 @@ impl Debugger {
|
||||
self.break_points()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|&(_, bp)| bp.is_enabled())
|
||||
.find(|&(_, bp)| match bp {
|
||||
.filter(|&(.., bp)| bp.is_enabled())
|
||||
.find(|&(.., bp)| match bp {
|
||||
#[cfg(not(feature = "no_position"))]
|
||||
BreakPoint::AtPosition { pos, .. } if pos.is_none() => false,
|
||||
#[cfg(not(feature = "no_position"))]
|
||||
@@ -361,26 +361,26 @@ impl Debugger {
|
||||
node.position() == *pos && _src == source
|
||||
}
|
||||
BreakPoint::AtFunctionName { name, .. } => match node {
|
||||
ASTNode::Expr(Expr::FnCall(x, _))
|
||||
| ASTNode::Stmt(Stmt::FnCall(x, _))
|
||||
| ASTNode::Stmt(Stmt::Expr(Expr::FnCall(x, _))) => x.name == *name,
|
||||
ASTNode::Expr(Expr::FnCall(x, ..))
|
||||
| ASTNode::Stmt(Stmt::FnCall(x, ..))
|
||||
| ASTNode::Stmt(Stmt::Expr(Expr::FnCall(x, ..))) => x.name == *name,
|
||||
_ => false,
|
||||
},
|
||||
BreakPoint::AtFunctionCall { name, args, .. } => match node {
|
||||
ASTNode::Expr(Expr::FnCall(x, _))
|
||||
| ASTNode::Stmt(Stmt::FnCall(x, _))
|
||||
| ASTNode::Stmt(Stmt::Expr(Expr::FnCall(x, _))) => {
|
||||
ASTNode::Expr(Expr::FnCall(x, ..))
|
||||
| ASTNode::Stmt(Stmt::FnCall(x, ..))
|
||||
| ASTNode::Stmt(Stmt::Expr(Expr::FnCall(x, ..))) => {
|
||||
x.args.len() == *args && x.name == *name
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
BreakPoint::AtProperty { name, .. } => match node {
|
||||
ASTNode::Expr(Expr::Property(x, _)) => x.2 == *name,
|
||||
ASTNode::Expr(Expr::Property(x, ..)) => x.2 == *name,
|
||||
_ => false,
|
||||
},
|
||||
})
|
||||
.map(|(i, _)| i)
|
||||
.map(|(i, ..)| i)
|
||||
}
|
||||
/// Get a slice of all [`BreakPoint`]'s.
|
||||
#[inline(always)]
|
||||
@@ -525,7 +525,7 @@ impl Engine {
|
||||
level,
|
||||
};
|
||||
|
||||
if let Some((_, ref on_debugger)) = self.debugger {
|
||||
if let Some((.., ref on_debugger)) = self.debugger {
|
||||
let command = on_debugger(&mut context, event, node, source, node.position())?;
|
||||
|
||||
match command {
|
||||
@@ -548,9 +548,9 @@ impl Engine {
|
||||
DebuggerCommand::FunctionExit => {
|
||||
// Bump a level if it is a function call
|
||||
let level = match node {
|
||||
ASTNode::Expr(Expr::FnCall(_, _))
|
||||
| ASTNode::Stmt(Stmt::FnCall(_, _))
|
||||
| ASTNode::Stmt(Stmt::Expr(Expr::FnCall(_, _))) => context.call_level() + 1,
|
||||
ASTNode::Expr(Expr::FnCall(..))
|
||||
| ASTNode::Stmt(Stmt::FnCall(..))
|
||||
| ASTNode::Stmt(Stmt::Expr(Expr::FnCall(..))) => context.call_level() + 1,
|
||||
_ => context.call_level(),
|
||||
};
|
||||
global.debugger.status = DebuggerStatus::FunctionExit(level);
|
||||
|
@@ -53,7 +53,7 @@ impl Engine {
|
||||
level: usize,
|
||||
) -> RhaiResultOf<(Target<'s>, Position)> {
|
||||
match expr {
|
||||
Expr::Variable(Some(_), _, _) => {
|
||||
Expr::Variable(Some(_), ..) => {
|
||||
self.search_scope_only(scope, global, state, lib, this_ptr, expr, level)
|
||||
}
|
||||
Expr::Variable(None, _var_pos, v) => match v.as_ref() {
|
||||
@@ -80,7 +80,7 @@ impl Engine {
|
||||
Ok((target.into(), *_var_pos))
|
||||
}
|
||||
Err(err) => Err(match *err {
|
||||
ERR::ErrorVariableNotFound(_, _) => ERR::ErrorVariableNotFound(
|
||||
ERR::ErrorVariableNotFound(..) => ERR::ErrorVariableNotFound(
|
||||
format!(
|
||||
"{}{}{}",
|
||||
namespace,
|
||||
@@ -155,7 +155,7 @@ impl Engine {
|
||||
}
|
||||
}
|
||||
_ if state.always_search_scope => (0, expr.start_position()),
|
||||
Expr::Variable(Some(i), pos, _) => (i.get() as usize, *pos),
|
||||
Expr::Variable(Some(i), pos, ..) => (i.get() as usize, *pos),
|
||||
Expr::Variable(None, pos, v) => (v.0.map(NonZeroUsize::get).unwrap_or(0), *pos),
|
||||
_ => unreachable!("Expr::Variable expected but gets {:?}", expr),
|
||||
};
|
||||
@@ -270,7 +270,7 @@ impl Engine {
|
||||
|
||||
// Function calls should account for a relatively larger portion of expressions because
|
||||
// binary operators are also function calls.
|
||||
if let Expr::FnCall(x, _) = expr {
|
||||
if let Expr::FnCall(x, ..) = expr {
|
||||
#[cfg(feature = "debugging")]
|
||||
let reset_debugger =
|
||||
self.run_debugger_with_reset(scope, global, state, lib, this_ptr, expr, level)?;
|
||||
@@ -304,7 +304,7 @@ impl Engine {
|
||||
.ok_or_else(|| ERR::ErrorUnboundThis(*var_pos).into())
|
||||
} else {
|
||||
self.search_namespace(scope, global, state, lib, this_ptr, expr, level)
|
||||
.map(|(val, _)| val.take_or_clone())
|
||||
.map(|(val, ..)| val.take_or_clone())
|
||||
};
|
||||
}
|
||||
|
||||
@@ -317,13 +317,13 @@ impl Engine {
|
||||
|
||||
let result = match expr {
|
||||
// Constants
|
||||
Expr::DynamicConstant(x, _) => Ok(x.as_ref().clone()),
|
||||
Expr::IntegerConstant(x, _) => Ok((*x).into()),
|
||||
Expr::DynamicConstant(x, ..) => Ok(x.as_ref().clone()),
|
||||
Expr::IntegerConstant(x, ..) => Ok((*x).into()),
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
Expr::FloatConstant(x, _) => Ok((*x).into()),
|
||||
Expr::StringConstant(x, _) => Ok(x.clone().into()),
|
||||
Expr::CharConstant(x, _) => Ok((*x).into()),
|
||||
Expr::BoolConstant(x, _) => Ok((*x).into()),
|
||||
Expr::FloatConstant(x, ..) => Ok((*x).into()),
|
||||
Expr::StringConstant(x, ..) => Ok(x.clone().into()),
|
||||
Expr::CharConstant(x, ..) => Ok((*x).into()),
|
||||
Expr::BoolConstant(x, ..) => Ok((*x).into()),
|
||||
Expr::Unit(_) => Ok(Dynamic::UNIT),
|
||||
|
||||
// `... ${...} ...`
|
||||
@@ -364,7 +364,7 @@ impl Engine {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Expr::Array(x, _) => {
|
||||
Expr::Array(x, ..) => {
|
||||
let mut arr = crate::Array::with_capacity(x.len());
|
||||
let mut result = Ok(Dynamic::UNIT);
|
||||
|
||||
@@ -402,7 +402,7 @@ impl Engine {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Expr::Map(x, _) => {
|
||||
Expr::Map(x, ..) => {
|
||||
let mut map = x.1.clone();
|
||||
let mut result = Ok(Dynamic::UNIT);
|
||||
|
||||
@@ -440,7 +440,7 @@ impl Engine {
|
||||
result.map(|_| map.into())
|
||||
}
|
||||
|
||||
Expr::And(x, _) => {
|
||||
Expr::And(x, ..) => {
|
||||
let lhs = self
|
||||
.eval_expr(scope, global, state, lib, this_ptr, &x.lhs, level)
|
||||
.and_then(|v| {
|
||||
@@ -463,7 +463,7 @@ impl Engine {
|
||||
}
|
||||
}
|
||||
|
||||
Expr::Or(x, _) => {
|
||||
Expr::Or(x, ..) => {
|
||||
let lhs = self
|
||||
.eval_expr(scope, global, state, lib, this_ptr, &x.lhs, level)
|
||||
.and_then(|v| {
|
||||
@@ -519,12 +519,12 @@ impl Engine {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Expr::Index(_, _, _) => {
|
||||
Expr::Index(..) => {
|
||||
self.eval_dot_index_chain(scope, global, state, lib, this_ptr, expr, level, None)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Expr::Dot(_, _, _) => {
|
||||
Expr::Dot(..) => {
|
||||
self.eval_dot_index_chain(scope, global, state, lib, this_ptr, expr, level, None)
|
||||
}
|
||||
|
||||
|
@@ -67,13 +67,13 @@ impl Engine {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
if matches!(stmt, Stmt::Import(_, _, _)) {
|
||||
if matches!(stmt, Stmt::Import(..)) {
|
||||
// Get the extra modules - see if any functions are marked global.
|
||||
// Without global functions, the extra modules never affect function resolution.
|
||||
if global
|
||||
.scan_imports_raw()
|
||||
.skip(imports_len)
|
||||
.any(|(_, m)| m.contains_indexed_global_functions())
|
||||
.any(|(.., m)| m.contains_indexed_global_functions())
|
||||
{
|
||||
if state.fn_resolution_caches_len() > orig_fn_resolution_caches_len {
|
||||
// When new module is imported with global functions and there is already
|
||||
@@ -162,10 +162,10 @@ impl Engine {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
self.check_data_size(&args[0], root.1)?;
|
||||
}
|
||||
Err(err) if matches!(*err, ERR::ErrorFunctionNotFound(ref f, _) if f.starts_with(op_assign)) =>
|
||||
Err(err) if matches!(*err, ERR::ErrorFunctionNotFound(ref f, ..) if f.starts_with(op_assign)) =>
|
||||
{
|
||||
// Expand to `var = var op rhs`
|
||||
let (value, _) = self.call_native_fn(
|
||||
let (value, ..) = self.call_native_fn(
|
||||
global, state, lib, op, hash_op, args, true, false, op_pos, level,
|
||||
)?;
|
||||
|
||||
@@ -211,7 +211,7 @@ impl Engine {
|
||||
// Popular branches are lifted out of the `match` statement into their own branches.
|
||||
|
||||
// Function calls should account for a relatively larger portion of statements.
|
||||
if let Stmt::FnCall(x, _) = stmt {
|
||||
if let Stmt::FnCall(x, ..) = stmt {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
self.inc_operations(&mut global.num_operations, stmt.position())?;
|
||||
|
||||
@@ -288,19 +288,19 @@ impl Engine {
|
||||
// Must be either `var[index] op= val` or `var.prop op= val`
|
||||
match lhs {
|
||||
// name op= rhs (handled above)
|
||||
Expr::Variable(_, _, _) => {
|
||||
Expr::Variable(..) => {
|
||||
unreachable!("Expr::Variable case is already handled")
|
||||
}
|
||||
// idx_lhs[idx_expr] op= rhs
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Expr::Index(_, _, _) => self
|
||||
Expr::Index(..) => self
|
||||
.eval_dot_index_chain(
|
||||
scope, global, state, lib, this_ptr, lhs, level, _new_val,
|
||||
)
|
||||
.map(|_| Dynamic::UNIT),
|
||||
// dot_lhs.dot_rhs op= rhs
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
Expr::Dot(_, _, _) => self
|
||||
Expr::Dot(..) => self
|
||||
.eval_dot_index_chain(
|
||||
scope, global, state, lib, this_ptr, lhs, level, _new_val,
|
||||
)
|
||||
@@ -331,13 +331,13 @@ impl Engine {
|
||||
.map(Dynamic::flatten),
|
||||
|
||||
// Block scope
|
||||
Stmt::Block(statements, _) if statements.is_empty() => Ok(Dynamic::UNIT),
|
||||
Stmt::Block(statements, _) => {
|
||||
Stmt::Block(statements, ..) if statements.is_empty() => Ok(Dynamic::UNIT),
|
||||
Stmt::Block(statements, ..) => {
|
||||
self.eval_stmt_block(scope, global, state, lib, this_ptr, statements, true, level)
|
||||
}
|
||||
|
||||
// If statement
|
||||
Stmt::If(expr, x, _) => {
|
||||
Stmt::If(expr, x, ..) => {
|
||||
let guard_val = self
|
||||
.eval_expr(scope, global, state, lib, this_ptr, expr, level)
|
||||
.and_then(|v| {
|
||||
@@ -370,7 +370,7 @@ impl Engine {
|
||||
}
|
||||
|
||||
// Switch statement
|
||||
Stmt::Switch(match_expr, x, _) => {
|
||||
Stmt::Switch(match_expr, x, ..) => {
|
||||
let SwitchCases {
|
||||
cases,
|
||||
def_case,
|
||||
@@ -414,8 +414,8 @@ impl Engine {
|
||||
let value = value.as_int().expect("`INT`");
|
||||
let mut result = Ok(None);
|
||||
|
||||
for (_, _, _, block) in
|
||||
ranges.iter().filter(|&&(start, end, inclusive, _)| {
|
||||
for (.., block) in
|
||||
ranges.iter().filter(|&&(start, end, inclusive, ..)| {
|
||||
(!inclusive && (start..end).contains(&value))
|
||||
|| (inclusive && (start..=end).contains(&value))
|
||||
})
|
||||
@@ -483,15 +483,15 @@ impl Engine {
|
||||
}
|
||||
|
||||
// Loop
|
||||
Stmt::While(Expr::Unit(_), body, _) => loop {
|
||||
Stmt::While(Expr::Unit(_), body, ..) => loop {
|
||||
if !body.is_empty() {
|
||||
match self
|
||||
.eval_stmt_block(scope, global, state, lib, this_ptr, body, true, level)
|
||||
{
|
||||
Ok(_) => (),
|
||||
Err(err) => match *err {
|
||||
ERR::LoopBreak(false, _) => (),
|
||||
ERR::LoopBreak(true, _) => break Ok(Dynamic::UNIT),
|
||||
ERR::LoopBreak(false, ..) => (),
|
||||
ERR::LoopBreak(true, ..) => break Ok(Dynamic::UNIT),
|
||||
_ => break Err(err),
|
||||
},
|
||||
}
|
||||
@@ -502,7 +502,7 @@ impl Engine {
|
||||
},
|
||||
|
||||
// While loop
|
||||
Stmt::While(expr, body, _) => loop {
|
||||
Stmt::While(expr, body, ..) => loop {
|
||||
let condition = self
|
||||
.eval_expr(scope, global, state, lib, this_ptr, expr, level)
|
||||
.and_then(|v| {
|
||||
@@ -520,8 +520,8 @@ impl Engine {
|
||||
{
|
||||
Ok(_) => (),
|
||||
Err(err) => match *err {
|
||||
ERR::LoopBreak(false, _) => (),
|
||||
ERR::LoopBreak(true, _) => break Ok(Dynamic::UNIT),
|
||||
ERR::LoopBreak(false, ..) => (),
|
||||
ERR::LoopBreak(true, ..) => break Ok(Dynamic::UNIT),
|
||||
_ => break Err(err),
|
||||
},
|
||||
}
|
||||
@@ -531,7 +531,7 @@ impl Engine {
|
||||
},
|
||||
|
||||
// Do loop
|
||||
Stmt::Do(body, expr, options, _) => loop {
|
||||
Stmt::Do(body, expr, options, ..) => loop {
|
||||
let is_while = !options.contains(AST_OPTION_NEGATED);
|
||||
|
||||
if !body.is_empty() {
|
||||
@@ -540,8 +540,8 @@ impl Engine {
|
||||
{
|
||||
Ok(_) => (),
|
||||
Err(err) => match *err {
|
||||
ERR::LoopBreak(false, _) => continue,
|
||||
ERR::LoopBreak(true, _) => break Ok(Dynamic::UNIT),
|
||||
ERR::LoopBreak(false, ..) => continue,
|
||||
ERR::LoopBreak(true, ..) => break Ok(Dynamic::UNIT),
|
||||
_ => break Err(err),
|
||||
},
|
||||
}
|
||||
@@ -563,7 +563,7 @@ impl Engine {
|
||||
},
|
||||
|
||||
// For loop
|
||||
Stmt::For(expr, x, _) => {
|
||||
Stmt::For(expr, x, ..) => {
|
||||
let (Ident { name: var_name, .. }, counter, statements) = x.as_ref();
|
||||
|
||||
let iter_result = self
|
||||
@@ -672,8 +672,8 @@ impl Engine {
|
||||
match result {
|
||||
Ok(_) => (),
|
||||
Err(err) => match *err {
|
||||
ERR::LoopBreak(false, _) => (),
|
||||
ERR::LoopBreak(true, _) => break,
|
||||
ERR::LoopBreak(false, ..) => (),
|
||||
ERR::LoopBreak(true, ..) => break,
|
||||
_ => {
|
||||
loop_result = Err(err);
|
||||
break;
|
||||
@@ -699,7 +699,7 @@ impl Engine {
|
||||
}
|
||||
|
||||
// Try/Catch statement
|
||||
Stmt::TryCatch(x, _) => {
|
||||
Stmt::TryCatch(x, ..) => {
|
||||
let TryCatchBlock {
|
||||
try_block,
|
||||
catch_var,
|
||||
@@ -716,7 +716,7 @@ impl Engine {
|
||||
Err(err) if !err.is_catchable() => Err(err),
|
||||
Err(mut err) => {
|
||||
let err_value = match *err {
|
||||
ERR::ErrorRuntime(ref x, _) => x.clone(),
|
||||
ERR::ErrorRuntime(ref x, ..) => x.clone(),
|
||||
|
||||
#[cfg(feature = "no_object")]
|
||||
_ => {
|
||||
@@ -773,7 +773,7 @@ impl Engine {
|
||||
Ok(_) => Ok(Dynamic::UNIT),
|
||||
Err(result_err) => match *result_err {
|
||||
// Re-throw exception
|
||||
ERR::ErrorRuntime(Dynamic(Union::Unit(_, _, _)), pos) => {
|
||||
ERR::ErrorRuntime(Dynamic(Union::Unit(..)), pos) => {
|
||||
err.set_position(pos);
|
||||
Err(err)
|
||||
}
|
||||
@@ -795,15 +795,15 @@ impl Engine {
|
||||
}
|
||||
|
||||
// Return value
|
||||
Stmt::Return(_, Some(expr), pos) => self
|
||||
Stmt::Return(.., Some(expr), pos) => self
|
||||
.eval_expr(scope, global, state, lib, this_ptr, expr, level)
|
||||
.and_then(|v| Err(ERR::Return(v.flatten(), *pos).into())),
|
||||
|
||||
// Empty return
|
||||
Stmt::Return(_, None, pos) => Err(ERR::Return(Dynamic::UNIT, *pos).into()),
|
||||
Stmt::Return(.., None, pos) => Err(ERR::Return(Dynamic::UNIT, *pos).into()),
|
||||
|
||||
// Let/const statement - shadowing disallowed
|
||||
Stmt::Var(_, x, _, pos) if !self.allow_shadowing() && scope.contains(&x.name) => {
|
||||
Stmt::Var(.., x, _, pos) if !self.allow_shadowing() && scope.contains(&x.name) => {
|
||||
Err(ERR::ErrorVariableExists(x.name.to_string(), *pos).into())
|
||||
}
|
||||
// Let/const statement
|
||||
@@ -924,7 +924,7 @@ impl Engine {
|
||||
let module_result = resolver
|
||||
.as_ref()
|
||||
.and_then(|r| match r.resolve_raw(self, global, &path, path_pos) {
|
||||
Err(err) if matches!(*err, ERR::ErrorModuleNotFound(_, _)) => None,
|
||||
Err(err) if matches!(*err, ERR::ErrorModuleNotFound(..)) => None,
|
||||
result => Some(result),
|
||||
})
|
||||
.or_else(|| {
|
||||
@@ -961,10 +961,10 @@ impl Engine {
|
||||
|
||||
// Export statement
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
Stmt::Export(x, _) => {
|
||||
Stmt::Export(x, ..) => {
|
||||
let (Ident { name, pos, .. }, Ident { name: alias, .. }) = x.as_ref();
|
||||
// Mark scope variables as public
|
||||
if let Some((index, _)) = scope.get_index(name) {
|
||||
if let Some((index, ..)) = scope.get_index(name) {
|
||||
scope.add_entry_alias(
|
||||
index,
|
||||
if alias.is_empty() { name } else { alias }.clone(),
|
||||
@@ -978,7 +978,7 @@ impl Engine {
|
||||
// Share statement
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Stmt::Share(name) => {
|
||||
if let Some((index, _)) = scope.get_index(name) {
|
||||
if let Some((index, ..)) = scope.get_index(name) {
|
||||
let val = scope.get_mut_by_index(index);
|
||||
|
||||
if !val.is_shared() {
|
||||
|
Reference in New Issue
Block a user