Always call native for op-assignment operators.
This commit is contained in:
parent
123e9d6901
commit
6f876e85cc
@ -1156,21 +1156,33 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let args = &mut [lhs_ptr_inner, &mut new_val];
|
let args = &mut [lhs_ptr_inner, &mut new_val];
|
||||||
|
let hash_fn = calc_native_fn_hash(
|
||||||
|
empty(),
|
||||||
|
op,
|
||||||
|
args.iter().map(|a| a.type_id()),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
match self.exec_fn_call(
|
match self.call_native_fn(
|
||||||
mods, state, lib, op, None, args, true, false, false,
|
mods, state, lib, op, hash_fn, args, true, false, op_pos,
|
||||||
op_pos, None, None, level,
|
None,
|
||||||
) {
|
) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(err) if matches!(err.as_ref(), EvalAltResult::ErrorFunctionNotFound(f, _) if f.starts_with(op)) =>
|
Err(err) if matches!(err.as_ref(), EvalAltResult::ErrorFunctionNotFound(f, _) if f.starts_with(op)) =>
|
||||||
{
|
{
|
||||||
// Expand to `var = var op rhs`
|
// Expand to `var = var op rhs`
|
||||||
let op = &op[..op.len() - 1]; // extract operator without =
|
let op = &op[..op.len() - 1]; // extract operator without =
|
||||||
|
let hash_fn = calc_native_fn_hash(
|
||||||
|
empty(),
|
||||||
|
op,
|
||||||
|
args.iter().map(|a| a.type_id()),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Run function
|
// Run function
|
||||||
let (value, _) = self.exec_fn_call(
|
let (value, _) = self.call_native_fn(
|
||||||
mods, state, lib, op, None, args, true, false,
|
mods, state, lib, op, hash_fn, args, true, false,
|
||||||
false, op_pos, None, None, level,
|
op_pos, None,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
*args[0] = value.flatten();
|
*args[0] = value.flatten();
|
||||||
@ -1277,21 +1289,29 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let args = &mut [lhs_ptr_inner, &mut new_val];
|
let args = &mut [lhs_ptr_inner, &mut new_val];
|
||||||
|
let hash_fn =
|
||||||
|
calc_native_fn_hash(empty(), op, args.iter().map(|a| a.type_id()))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
match self.exec_fn_call(
|
match self.call_native_fn(
|
||||||
mods, state, lib, op, None, args, true, false, false, op_pos, None,
|
mods, state, lib, op, hash_fn, args, true, false, op_pos, None,
|
||||||
None, level,
|
|
||||||
) {
|
) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(err) if matches!(err.as_ref(), EvalAltResult::ErrorFunctionNotFound(f, _) if f.starts_with(op)) =>
|
Err(err) if matches!(err.as_ref(), EvalAltResult::ErrorFunctionNotFound(f, _) if f.starts_with(op)) =>
|
||||||
{
|
{
|
||||||
// Expand to `var = var op rhs`
|
// Expand to `var = var op rhs`
|
||||||
let op = &op[..op.len() - 1]; // extract operator without =
|
let op = &op[..op.len() - 1]; // extract operator without =
|
||||||
|
let hash_fn = calc_native_fn_hash(
|
||||||
|
empty(),
|
||||||
|
op,
|
||||||
|
args.iter().map(|a| a.type_id()),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Run function
|
// Run function
|
||||||
let (value, _) = self.exec_fn_call(
|
let (value, _) = self.call_native_fn(
|
||||||
mods, state, lib, op, None, args, true, false, false,
|
mods, state, lib, op, hash_fn, args, true, false, op_pos,
|
||||||
op_pos, None, None, level,
|
None,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
*args[0] = value.flatten();
|
*args[0] = value.flatten();
|
||||||
@ -1757,12 +1777,9 @@ impl Engine {
|
|||||||
|
|
||||||
for value in rhs_value.iter_mut() {
|
for value in rhs_value.iter_mut() {
|
||||||
let args = &mut [&mut lhs_value.clone(), value];
|
let args = &mut [&mut lhs_value.clone(), value];
|
||||||
|
|
||||||
// Qualifiers (none) + function name + number of arguments + argument `TypeId`'s.
|
|
||||||
let hash_fn =
|
let hash_fn =
|
||||||
calc_native_fn_hash(empty(), OP_EQUALS, args.iter().map(|a| a.type_id()))
|
calc_native_fn_hash(empty(), OP_EQUALS, args.iter().map(|a| a.type_id()))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let pos = rhs.position();
|
let pos = rhs.position();
|
||||||
|
|
||||||
if self
|
if self
|
||||||
@ -2090,10 +2107,11 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let args = &mut [lhs_ptr_inner, &mut rhs_val];
|
let args = &mut [lhs_ptr_inner, &mut rhs_val];
|
||||||
|
let hash_fn =
|
||||||
|
calc_native_fn_hash(empty(), op, args.iter().map(|a| a.type_id())).unwrap();
|
||||||
|
|
||||||
match self.exec_fn_call(
|
match self.call_native_fn(
|
||||||
mods, state, lib, op, None, args, true, false, false, *op_pos, None, None,
|
mods, state, lib, op, hash_fn, args, true, false, *op_pos, None,
|
||||||
level,
|
|
||||||
) {
|
) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(err) if matches!(err.as_ref(), EvalAltResult::ErrorFunctionNotFound(f, _) if f.starts_with(op.as_ref())) =>
|
Err(err) if matches!(err.as_ref(), EvalAltResult::ErrorFunctionNotFound(f, _) if f.starts_with(op.as_ref())) =>
|
||||||
@ -2102,9 +2120,8 @@ impl Engine {
|
|||||||
let op = &op[..op.len() - 1]; // extract operator without =
|
let op = &op[..op.len() - 1]; // extract operator without =
|
||||||
|
|
||||||
// Run function
|
// Run function
|
||||||
let (value, _) = self.exec_fn_call(
|
let (value, _) = self.call_native_fn(
|
||||||
mods, state, lib, op, None, args, false, false, false, *op_pos,
|
mods, state, lib, op, hash_fn, args, false, false, *op_pos, None,
|
||||||
None, None, level,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
*args[0] = value.flatten();
|
*args[0] = value.flatten();
|
||||||
|
@ -214,17 +214,20 @@ impl Engine {
|
|||||||
|
|
||||||
// Try all permutations with `Dynamic` wildcards
|
// Try all permutations with `Dynamic` wildcards
|
||||||
_ => {
|
_ => {
|
||||||
// Qualifiers (none) + function name + number of arguments + argument `TypeId`'s.
|
hash = calc_native_fn_hash(
|
||||||
let arg_types = args.iter().enumerate().map(|(i, a)| {
|
empty(),
|
||||||
let mask = 1usize << (num_args - i - 1);
|
fn_name,
|
||||||
if bitmask & mask != 0 {
|
args.iter().enumerate().map(|(i, a)| {
|
||||||
// Replace with `Dynamic`
|
let mask = 1usize << (num_args - i - 1);
|
||||||
TypeId::of::<Dynamic>()
|
if bitmask & mask != 0 {
|
||||||
} else {
|
// Replace with `Dynamic`
|
||||||
a.type_id()
|
TypeId::of::<Dynamic>()
|
||||||
}
|
} else {
|
||||||
});
|
a.type_id()
|
||||||
hash = calc_native_fn_hash(empty(), fn_name, arg_types).unwrap();
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Stop when all permutations are exhausted
|
// Stop when all permutations are exhausted
|
||||||
if hash == hash_fn {
|
if hash == hash_fn {
|
||||||
@ -613,9 +616,8 @@ impl Engine {
|
|||||||
ensure_no_data_race(fn_name, args, is_ref)?;
|
ensure_no_data_race(fn_name, args, is_ref)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Qualifiers (none) + function name + number of arguments + argument `TypeId`'s.
|
let hash_fn =
|
||||||
let arg_types = args.iter().map(|a| a.type_id());
|
calc_native_fn_hash(empty(), fn_name, args.iter().map(|a| a.type_id())).unwrap();
|
||||||
let hash_fn = calc_native_fn_hash(empty(), fn_name, arg_types).unwrap();
|
|
||||||
|
|
||||||
match fn_name {
|
match fn_name {
|
||||||
// type_of
|
// type_of
|
||||||
|
@ -1855,7 +1855,6 @@ impl Module {
|
|||||||
|
|
||||||
// Index all variables
|
// Index all variables
|
||||||
module.variables.iter().for_each(|(var_name, value)| {
|
module.variables.iter().for_each(|(var_name, value)| {
|
||||||
// Qualifiers + variable name
|
|
||||||
let hash_var =
|
let hash_var =
|
||||||
crate::calc_script_fn_hash(qualifiers.iter().map(|&v| v), var_name, 0).unwrap();
|
crate::calc_script_fn_hash(qualifiers.iter().map(|&v| v), var_name, 0).unwrap();
|
||||||
variables.insert(hash_var, value.clone());
|
variables.insert(hash_var, value.clone());
|
||||||
@ -1888,7 +1887,6 @@ impl Module {
|
|||||||
functions.insert(hash, func.clone());
|
functions.insert(hash, func.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Qualifiers + function name + number of arguments.
|
|
||||||
let hash_qualified_script =
|
let hash_qualified_script =
|
||||||
crate::calc_script_fn_hash(qualifiers.iter().cloned(), name, *params)
|
crate::calc_script_fn_hash(qualifiers.iter().cloned(), name, *params)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -347,7 +347,6 @@ fn parse_fn_call(
|
|||||||
let qualifiers = modules.iter().map(|m| m.name.as_str());
|
let qualifiers = modules.iter().map(|m| m.name.as_str());
|
||||||
calc_script_fn_hash(qualifiers, &id, 0)
|
calc_script_fn_hash(qualifiers, &id, 0)
|
||||||
} else {
|
} else {
|
||||||
// Qualifiers (none) + function name + no parameters.
|
|
||||||
calc_script_fn_hash(empty(), &id, 0)
|
calc_script_fn_hash(empty(), &id, 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -399,7 +398,6 @@ fn parse_fn_call(
|
|||||||
let qualifiers = modules.iter().map(|m| m.name.as_str());
|
let qualifiers = modules.iter().map(|m| m.name.as_str());
|
||||||
calc_script_fn_hash(qualifiers, &id, args.len())
|
calc_script_fn_hash(qualifiers, &id, args.len())
|
||||||
} else {
|
} else {
|
||||||
// Qualifiers (none) + function name + number of arguments.
|
|
||||||
calc_script_fn_hash(empty(), &id, args.len())
|
calc_script_fn_hash(empty(), &id, args.len())
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1016,7 +1014,6 @@ fn parse_primary(
|
|||||||
});
|
});
|
||||||
|
|
||||||
lib.insert(
|
lib.insert(
|
||||||
// Qualifiers (none) + function name + number of arguments.
|
|
||||||
calc_script_fn_hash(empty(), &func.name, func.params.len()).unwrap(),
|
calc_script_fn_hash(empty(), &func.name, func.params.len()).unwrap(),
|
||||||
func,
|
func,
|
||||||
);
|
);
|
||||||
@ -1246,7 +1243,6 @@ fn parse_primary(
|
|||||||
}
|
}
|
||||||
.map(|x| match x.as_mut() {
|
.map(|x| match x.as_mut() {
|
||||||
(_, Some((ref mut hash, ref mut namespace)), Ident { name, .. }) => {
|
(_, Some((ref mut hash, ref mut namespace)), Ident { name, .. }) => {
|
||||||
// Qualifiers + variable name
|
|
||||||
*hash =
|
*hash =
|
||||||
calc_script_fn_hash(namespace.iter().map(|v| v.name.as_str()), name, 0).unwrap();
|
calc_script_fn_hash(namespace.iter().map(|v| v.name.as_str()), name, 0).unwrap();
|
||||||
|
|
||||||
@ -2621,8 +2617,6 @@ fn parse_stmt(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let func = parse_fn(input, &mut new_state, lib, access, settings, _comments)?;
|
let func = parse_fn(input, &mut new_state, lib, access, settings, _comments)?;
|
||||||
|
|
||||||
// Qualifiers (none) + function name + number of arguments.
|
|
||||||
let hash = calc_script_fn_hash(empty(), &func.name, func.params.len()).unwrap();
|
let hash = calc_script_fn_hash(empty(), &func.name, func.params.len()).unwrap();
|
||||||
|
|
||||||
if lib.contains_key(&hash) {
|
if lib.contains_key(&hash) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user