Minor housekeeping.

This commit is contained in:
Stephen Chung
2022-02-24 10:36:20 +08:00
parent 2f5ce2fe5b
commit 73f10b8adc
15 changed files with 128 additions and 135 deletions

View File

@@ -187,9 +187,9 @@ impl Engine {
self.call_indexer_set(
global, state, lib, target, idx, new_val, is_ref_mut, level,
)
.or_else(|idx_err| match *idx_err {
.or_else(|e| match *e {
ERR::ErrorIndexingType(..) => Ok((Dynamic::UNIT, false)),
_ => Err(idx_err),
_ => Err(e),
})?;
}
@@ -333,28 +333,25 @@ impl Engine {
self.call_indexer_get(
global, state, lib, target, &mut prop, level,
)
.map_err(
|idx_err| match *idx_err {
.map_err(|e| {
match *e {
ERR::ErrorIndexingType(..) => err,
_ => idx_err,
},
)
_ => e,
}
})
}
_ => Err(err),
})?;
self.eval_op_assignment(
global,
state,
lib,
op_info,
op_pos,
&mut (&mut orig_val).into(),
root,
new_val,
level,
)
.map_err(|err| err.fill_position(new_pos))?;
{
let orig_val = &mut (&mut orig_val).into();
self.eval_op_assignment(
global, state, lib, op_info, op_pos, orig_val, root, new_val,
level,
)
.map_err(|err| err.fill_position(new_pos))?;
}
new_val = orig_val;
}
@@ -373,12 +370,10 @@ impl Engine {
self.call_indexer_set(
global, state, lib, target, idx, new_val, is_ref_mut, level,
)
.map_err(
|idx_err| match *idx_err {
ERR::ErrorIndexingType(..) => err,
_ => idx_err,
},
)
.map_err(|e| match *e {
ERR::ErrorIndexingType(..) => err,
_ => e,
})
}
_ => Err(err),
})
@@ -403,11 +398,9 @@ impl Engine {
self.call_indexer_get(
global, state, lib, target, &mut prop, level,
)
.map_err(|idx_err| {
match *idx_err {
ERR::ErrorIndexingType(..) => err,
_ => idx_err,
}
.map_err(|e| match *e {
ERR::ErrorIndexingType(..) => err,
_ => e,
})
}
_ => Err(err),
@@ -502,39 +495,28 @@ impl Engine {
global, state, lib, target, &mut prop, level,
)
.map_err(
|idx_err| match *idx_err {
|e| match *e {
ERR::ErrorIndexingType(..) => err,
_ => idx_err,
_ => e,
},
)
}
_ => Err(err),
})?;
let val = &mut val;
let val = &mut (&mut val).into();
let (result, may_be_changed) = self
.eval_dot_index_chain_helper(
global,
state,
lib,
this_ptr,
&mut val.into(),
root,
rhs,
&x.rhs,
*term,
idx_values,
rhs_chain,
level,
new_val,
global, state, lib, this_ptr, val, root, rhs, &x.rhs,
*term, idx_values, rhs_chain, level, new_val,
)
.map_err(|err| err.fill_position(*x_pos))?;
// Feed the value back via a setter just in case it has been updated
if may_be_changed {
// Re-use args because the first &mut parameter will not be consumed
let mut arg_values = [target.as_mut(), val];
let mut arg_values = [target.as_mut(), val.as_mut()];
let args = &mut arg_values;
self.exec_fn_call(
None, global, state, lib, setter, hash_set, args,
@@ -550,13 +532,13 @@ impl Engine {
global, state, lib, target, idx, new_val,
is_ref_mut, level,
)
.or_else(|idx_err| match *idx_err {
.or_else(|e| match *e {
// If there is no setter, no need to feed it
// back because the property is read-only
ERR::ErrorIndexingType(..) => {
Ok((Dynamic::UNIT, false))
}
_ => Err(idx_err),
_ => Err(e),
})
}
_ => Err(err),
@@ -584,11 +566,11 @@ impl Engine {
#[cfg(feature = "debugging")]
global.debugger.reset_status(reset_debugger);
let val = &mut result?.0;
let target = &mut val.into();
let (val, _) = &mut result?;
let val = &mut val.into();
self.eval_dot_index_chain_helper(
global, state, lib, this_ptr, target, root, rhs, &x.rhs, *term,
global, state, lib, this_ptr, val, root, rhs, &x.rhs, *term,
idx_values, rhs_chain, level, new_val,
)
.map_err(|err| err.fill_position(pos))

View File

@@ -419,17 +419,13 @@ impl Engine {
};
#[cfg(not(feature = "unchecked"))]
let val_sizes = Self::calc_data_sizes(&value, true);
let delta = Self::calc_data_sizes(&value, true);
*map.get_mut(key).unwrap() = value;
#[cfg(not(feature = "unchecked"))]
if self.has_data_size_limit() {
sizes = (
sizes.0 + val_sizes.0,
sizes.1 + val_sizes.1,
sizes.2 + val_sizes.2,
);
sizes = (sizes.0 + delta.0, sizes.1 + delta.1, sizes.2 + delta.2);
self.raise_err_if_over_data_size_limit(sizes, value_expr.position())?;
}
}

View File

@@ -17,8 +17,10 @@ pub type GlobalConstants =
// # Implementation Notes
//
// This implementation for imported [modules][crate::Module] splits the module names from the shared
// modules to improve data locality. Most usage will be looking up a particular key from the list
// and then getting the module that corresponds to that key.
// modules to improve data locality.
//
// Most usage will be looking up a particular key from the list and then getting the module that
// corresponds to that key.
#[derive(Clone)]
pub struct GlobalRuntimeState<'a> {
/// Stack of module names.
@@ -103,7 +105,8 @@ impl GlobalRuntimeState<'_> {
pub fn get_shared_import(&self, index: usize) -> Option<crate::Shared<crate::Module>> {
self.modules.get(index).cloned()
}
/// Get a mutable reference to the globally-imported [crate::Module][crate::Module] at a particular index.
/// Get a mutable reference to the globally-imported [crate::Module][crate::Module] at a
/// particular index.
///
/// Not available under `no_module`.
#[cfg(not(feature = "no_module"))]
@@ -190,7 +193,8 @@ impl GlobalRuntimeState<'_> {
) -> impl Iterator<Item = (&Identifier, &crate::Shared<crate::Module>)> {
self.keys.iter().zip(self.modules.iter())
}
/// Does the specified function hash key exist in the stack of globally-imported [modules][crate::Module]?
/// Does the specified function hash key exist in the stack of globally-imported
/// [modules][crate::Module]?
///
/// Not available under `no_module`.
#[cfg(not(feature = "no_module"))]
@@ -200,7 +204,8 @@ impl GlobalRuntimeState<'_> {
pub fn contains_qualified_fn(&self, hash: u64) -> bool {
self.modules.iter().any(|m| m.contains_qualified_fn(hash))
}
/// Get the specified function via its hash key from the stack of globally-imported [modules][crate::Module].
/// Get the specified function via its hash key from the stack of globally-imported
/// [modules][crate::Module].
///
/// Not available under `no_module`.
#[cfg(not(feature = "no_module"))]

View File

@@ -257,16 +257,11 @@ impl Engine {
#[cfg(not(feature = "unchecked"))]
self.inc_operations(&mut global.num_operations, pos)?;
let root = (var_name, pos);
let lhs_ptr = &mut lhs_ptr;
self.eval_op_assignment(
global,
state,
lib,
*op_info,
*op_pos,
&mut lhs_ptr,
(var_name, pos),
rhs_val,
level,
global, state, lib, *op_info, *op_pos, lhs_ptr, root, rhs_val, level,
)
.map_err(|err| err.fill_position(rhs.start_position()))
.map(|_| Dynamic::UNIT)
@@ -392,8 +387,8 @@ impl Engine {
let hash = hasher.finish();
// First check hashes
if let Some(t) = cases.get(&hash) {
let cond_result = t
if let Some(case_block) = cases.get(&hash) {
let cond_result = case_block
.condition
.as_ref()
.map(|cond| {
@@ -410,7 +405,7 @@ impl Engine {
.unwrap_or(Ok(true));
match cond_result {
Ok(true) => Ok(Some(&t.statements)),
Ok(true) => Ok(Some(&case_block.statements)),
Ok(false) => Ok(None),
_ => cond_result.map(|_| None),
}