Code cleanup.

This commit is contained in:
Stephen Chung
2022-10-30 22:16:09 +08:00
parent dc5e80c821
commit 32493524ed
9 changed files with 144 additions and 150 deletions

View File

@@ -270,8 +270,8 @@ impl Engine {
let args = &mut [target.as_mut()];
let (mut orig_val, ..) = self
.exec_native_fn_call(
global, caches, lib, getter, *hash_get, args, is_ref_mut,
false, *pos, level,
global, caches, lib, getter, None, *hash_get, args, is_ref_mut,
*pos, level,
)
.or_else(|err| match *err {
// Try an indexer if property does not exist
@@ -304,7 +304,7 @@ impl Engine {
let args = &mut [target.as_mut(), &mut new_val];
self.exec_native_fn_call(
global, caches, lib, setter, *hash_set, args, is_ref_mut, false, *pos,
global, caches, lib, setter, None, *hash_set, args, is_ref_mut, *pos,
level,
)
.or_else(|err| match *err {
@@ -331,7 +331,7 @@ impl Engine {
let ((getter, hash_get), _, name) = &**x;
let args = &mut [target.as_mut()];
self.exec_native_fn_call(
global, caches, lib, getter, *hash_get, args, is_ref_mut, false, *pos,
global, caches, lib, getter, None, *hash_get, args, is_ref_mut, *pos,
level,
)
.map_or_else(
@@ -430,8 +430,8 @@ impl Engine {
// Assume getters are always pure
let (mut val, ..) = self
.exec_native_fn_call(
global, caches, lib, getter, *hash_get, args, is_ref_mut,
false, pos, level,
global, caches, lib, getter, None, *hash_get, args,
is_ref_mut, pos, level,
)
.or_else(|err| match *err {
// Try an indexer if property does not exist
@@ -466,8 +466,8 @@ impl Engine {
let mut arg_values = [target.as_mut(), val.as_mut()];
let args = &mut arg_values;
self.exec_native_fn_call(
global, caches, lib, setter, *hash_set, args, is_ref_mut,
false, pos, level,
global, caches, lib, setter, None, *hash_set, args,
is_ref_mut, pos, level,
)
.or_else(
|err| match *err {
@@ -765,7 +765,7 @@ impl Engine {
let level = level + 1;
self.exec_native_fn_call(
global, caches, lib, fn_name, hash, args, true, false, pos, level,
global, caches, lib, fn_name, None, hash, args, true, pos, level,
)
.map(|(r, ..)| r)
}
@@ -790,7 +790,7 @@ impl Engine {
let level = level + 1;
self.exec_native_fn_call(
global, caches, lib, fn_name, hash, args, is_ref_mut, false, pos, level,
global, caches, lib, fn_name, None, hash, args, is_ref_mut, pos, level,
)
}

View File

@@ -130,8 +130,8 @@ impl Engine {
let OpAssignment {
hash_op_assign,
hash_op,
op_assign,
op,
op_assign: op_assign_token,
op: op_token,
pos: op_pos,
} = op_info;
@@ -142,27 +142,31 @@ impl Engine {
let level = level + 1;
if self.fast_operators() {
if let Some(func) = get_builtin_op_assignment_fn(op_assign, args[0], args[1]) {
if let Some(func) = get_builtin_op_assignment_fn(op_assign_token, args[0], args[1])
{
// Built-in found
let op = op_assign.literal_syntax();
let op = op_assign_token.literal_syntax();
let context = (self, op, None, &*global, lib, *op_pos, level).into();
return func(context, args).map(|_| ());
}
}
let op_assign = op_assign.literal_syntax();
let op = op.literal_syntax();
let op_assign = op_assign_token.literal_syntax();
let op = op_token.literal_syntax();
let token = Some(op_assign_token);
match self.exec_native_fn_call(
global, caches, lib, op_assign, hash, args, true, true, *op_pos, level,
global, caches, lib, op_assign, token, hash, args, true, *op_pos, level,
) {
Ok(_) => (),
Err(err) if matches!(*err, ERR::ErrorFunctionNotFound(ref f, ..) if f.starts_with(op_assign)) =>
{
// Expand to `var = var op rhs`
let token = Some(op_token);
*args[0] = self
.exec_native_fn_call(
global, caches, lib, op, *hash_op, args, true, false, *op_pos, level,
global, caches, lib, op, token, *hash_op, args, true, *op_pos, level,
)
.map_err(|err| err.fill_position(op_info.pos))?
.0