Minor refactor.
This commit is contained in:
parent
4b4b7a753b
commit
d36e2d22d1
@ -335,7 +335,6 @@ impl Engine {
|
|||||||
/// * `Ok(None)`: parsing complete and there are no more symbols to match.
|
/// * `Ok(None)`: parsing complete and there are no more symbols to match.
|
||||||
/// * `Ok(Some(symbol))`: the next symbol to match, which can also be `$expr$`, `$ident$` or `$block$`.
|
/// * `Ok(Some(symbol))`: the next symbol to match, which can also be `$expr$`, `$ident$` or `$block$`.
|
||||||
/// * `Err(ParseError)`: error that is reflected back to the [`Engine`], normally `ParseError(ParseErrorType::BadInput(LexError::ImproperSymbol(message)), Position::NONE)` to indicate a syntax error, but it can be any [`ParseError`].
|
/// * `Err(ParseError)`: error that is reflected back to the [`Engine`], normally `ParseError(ParseErrorType::BadInput(LexError::ImproperSymbol(message)), Position::NONE)` to indicate a syntax error, but it can be any [`ParseError`].
|
||||||
///
|
|
||||||
pub fn register_custom_syntax_raw(
|
pub fn register_custom_syntax_raw(
|
||||||
&mut self,
|
&mut self,
|
||||||
key: impl Into<Identifier>,
|
key: impl Into<Identifier>,
|
||||||
|
@ -313,7 +313,7 @@ impl Engine {
|
|||||||
name: impl AsRef<str>,
|
name: impl AsRef<str>,
|
||||||
hash: u64,
|
hash: u64,
|
||||||
args: &mut FnCallArgs,
|
args: &mut FnCallArgs,
|
||||||
is_method_call: bool,
|
is_ref_mut: bool,
|
||||||
is_op_assign: bool,
|
is_op_assign: bool,
|
||||||
pos: Position,
|
pos: Position,
|
||||||
) -> Result<(Dynamic, bool), Box<EvalAltResult>> {
|
) -> Result<(Dynamic, bool), Box<EvalAltResult>> {
|
||||||
@ -331,7 +331,8 @@ impl Engine {
|
|||||||
|
|
||||||
// Calling pure function but the first argument is a reference?
|
// Calling pure function but the first argument is a reference?
|
||||||
let mut backup: Option<ArgBackup> = None;
|
let mut backup: Option<ArgBackup> = None;
|
||||||
if is_method_call && func.is_pure() && !args.is_empty() {
|
if is_ref_mut && func.is_pure() && !args.is_empty() {
|
||||||
|
// Clone the first argument
|
||||||
backup = Some(ArgBackup::new());
|
backup = Some(ArgBackup::new());
|
||||||
backup
|
backup
|
||||||
.as_mut()
|
.as_mut()
|
||||||
@ -397,6 +398,8 @@ impl Engine {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Error handling
|
||||||
|
|
||||||
match name {
|
match name {
|
||||||
// index getter function not found?
|
// index getter function not found?
|
||||||
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
|
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
|
||||||
|
@ -22,9 +22,6 @@ use std::{
|
|||||||
ops::DerefMut,
|
ops::DerefMut,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
|
||||||
use crate::engine::KEYWORD_IS_SHARED;
|
|
||||||
|
|
||||||
/// Level of optimization performed.
|
/// Level of optimization performed.
|
||||||
#[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
|
#[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
|
||||||
pub enum OptimizationLevel {
|
pub enum OptimizationLevel {
|
||||||
@ -986,7 +983,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, chaining: bool) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
KEYWORD_IS_SHARED if arg_values.len() == 1 => {
|
crate::engine::KEYWORD_IS_SHARED if arg_values.len() == 1 => {
|
||||||
state.set_dirty();
|
state.set_dirty();
|
||||||
*expr = Expr::from_dynamic(Dynamic::FALSE, *pos);
|
*expr = Expr::from_dynamic(Dynamic::FALSE, *pos);
|
||||||
return;
|
return;
|
||||||
@ -1046,7 +1043,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, chaining: bool) {
|
|||||||
let result = match x.name.as_str() {
|
let result = match x.name.as_str() {
|
||||||
KEYWORD_TYPE_OF if arg_values.len() == 1 => Some(state.engine.map_type_name(arg_values[0].type_name()).into()),
|
KEYWORD_TYPE_OF if arg_values.len() == 1 => Some(state.engine.map_type_name(arg_values[0].type_name()).into()),
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
KEYWORD_IS_SHARED if arg_values.len() == 1 => Some(Dynamic::FALSE),
|
crate::engine::KEYWORD_IS_SHARED if arg_values.len() == 1 => Some(Dynamic::FALSE),
|
||||||
_ => state.call_fn_with_constant_arguments(&x.name, arg_values)
|
_ => state.call_fn_with_constant_arguments(&x.name, arg_values)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ fn test_fn_ptr_make_closure() -> Result<(), Box<EvalAltResult>> {
|
|||||||
|
|
||||||
let fn_ptr = engine.eval_ast::<FnPtr>(&ast)?;
|
let fn_ptr = engine.eval_ast::<FnPtr>(&ast)?;
|
||||||
|
|
||||||
move |x: INT| -> Result<String, Box<EvalAltResult>> { fn_ptr.call(&engine, &ast, (x,)) }
|
move |x: INT| -> Result<String, _> { fn_ptr.call(&engine, &ast, (x,)) }
|
||||||
};
|
};
|
||||||
|
|
||||||
// 'f' captures: the Engine, the AST, and the closure
|
// 'f' captures: the Engine, the AST, and the closure
|
||||||
|
Loading…
Reference in New Issue
Block a user