Add eval_expression_tree_raw.
This commit is contained in:
@@ -185,6 +185,10 @@ impl Engine {
|
||||
///
|
||||
/// Not available under `no_function`.
|
||||
///
|
||||
/// # WARNING - Unstable API
|
||||
///
|
||||
/// This API is volatile and may change in the future.
|
||||
///
|
||||
/// # WARNING - Low Level API
|
||||
///
|
||||
/// This function is _extremely_ low level.
|
||||
@@ -202,6 +206,7 @@ impl Engine {
|
||||
/// Do not use the arguments after this call. If they are needed afterwards, clone them _before_
|
||||
/// calling this function.
|
||||
#[cfg(feature = "internals")]
|
||||
#[deprecated = "This API is NOT deprecated, but it is considered volatile and may change in the future."]
|
||||
#[inline(always)]
|
||||
pub fn call_fn_raw_raw(
|
||||
&self,
|
||||
|
@@ -74,6 +74,28 @@ impl Expression<'_> {
|
||||
pub fn eval_with_context(&self, context: &mut EvalContext) -> RhaiResult {
|
||||
context.eval_expression_tree(self)
|
||||
}
|
||||
/// Evaluate this [expression tree][Expression] within an [evaluation context][`EvalContext`].
|
||||
///
|
||||
/// The following option is available:
|
||||
///
|
||||
/// * whether to rewind the [`Scope`] after evaluation if the expression is a [`StmtBlock`][crate::ast::StmtBlock]
|
||||
///
|
||||
/// # WARNING - Unstable API
|
||||
///
|
||||
/// This API is volatile and may change in the future.
|
||||
///
|
||||
/// # WARNING - Low Level API
|
||||
///
|
||||
/// This function is _extremely_ low level. It evaluates an expression from an [`AST`][crate::AST].
|
||||
#[inline(always)]
|
||||
pub fn eval_with_context_raw(
|
||||
&self,
|
||||
context: &mut EvalContext,
|
||||
rewind_scope: bool,
|
||||
) -> RhaiResult {
|
||||
#[allow(deprecated)]
|
||||
context.eval_expression_tree_raw(self, rewind_scope)
|
||||
}
|
||||
/// Get the value of this expression if it is a variable name or a string constant.
|
||||
///
|
||||
/// Returns [`None`] also if the constant is not of the specified type.
|
||||
|
@@ -150,6 +150,32 @@ impl<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'pg, '
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
#[inline(always)]
|
||||
pub fn eval_expression_tree(&mut self, expr: &crate::Expression) -> crate::RhaiResult {
|
||||
#[allow(deprecated)]
|
||||
self.eval_expression_tree_raw(expr, true)
|
||||
}
|
||||
/// Evaluate an [expression tree][crate::Expression] within this [evaluation context][`EvalContext`].
|
||||
///
|
||||
/// The following option is available:
|
||||
///
|
||||
/// * whether to rewind the [`Scope`] after evaluation if the expression is a [`StmtBlock`][crate::ast::StmtBlock]
|
||||
///
|
||||
/// # WARNING - Unstable API
|
||||
///
|
||||
/// This API is volatile and may change in the future.
|
||||
///
|
||||
/// # WARNING - Low Level API
|
||||
///
|
||||
/// This function is _extremely_ low level. It evaluates an expression from an [`AST`][crate::AST].
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
#[deprecated = "This API is NOT deprecated, but it is considered volatile and may change in the future."]
|
||||
#[inline]
|
||||
pub fn eval_expression_tree_raw(
|
||||
&mut self,
|
||||
expr: &crate::Expression,
|
||||
rewind_scope: bool,
|
||||
) -> crate::RhaiResult {
|
||||
let expr: &crate::ast::Expr = expr;
|
||||
|
||||
let mut new_caches = Caches::new();
|
||||
|
||||
let caches = match self.caches.as_mut() {
|
||||
@@ -157,14 +183,26 @@ impl<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'pg, '
|
||||
None => &mut new_caches,
|
||||
};
|
||||
|
||||
self.engine.eval_expr(
|
||||
self.scope,
|
||||
self.global,
|
||||
caches,
|
||||
self.lib,
|
||||
self.this_ptr,
|
||||
expr,
|
||||
self.level,
|
||||
)
|
||||
match expr {
|
||||
crate::Expr::Stmt(statements) => self.engine.eval_stmt_block(
|
||||
self.scope,
|
||||
self.global,
|
||||
caches,
|
||||
self.lib,
|
||||
self.this_ptr,
|
||||
&statements,
|
||||
rewind_scope,
|
||||
self.level,
|
||||
),
|
||||
_ => self.engine.eval_expr(
|
||||
self.scope,
|
||||
self.global,
|
||||
caches,
|
||||
self.lib,
|
||||
self.this_ptr,
|
||||
expr,
|
||||
self.level,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1236,7 +1236,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) {
|
||||
if x.scope_may_be_changed {
|
||||
state.propagate_constants = false;
|
||||
}
|
||||
x.inputs.iter_mut().for_each(|expr| optimize_expr(expr, state, false));
|
||||
// Do not optimize custom syntax expressions as you won't know how they would be called
|
||||
}
|
||||
|
||||
// All other expressions - skip
|
||||
|
@@ -2336,7 +2336,7 @@ impl<'a> Iterator for TokenIterator<'a> {
|
||||
}
|
||||
// Reserved keyword/symbol
|
||||
Some((Token::Reserved(s), pos)) => (match
|
||||
(&*s,
|
||||
(&*s,
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
(!self.engine.custom_keywords.is_empty() && self.engine.custom_keywords.contains_key(&*s)),
|
||||
#[cfg(feature = "no_custom_syntax")]
|
||||
|
Reference in New Issue
Block a user