From 280010c4272b8a998e8f4a2eae819b0be093d044 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 28 Dec 2021 12:00:01 +0800 Subject: [PATCH] Fix builds. --- src/func/call.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ src/func/script.rs | 43 ------------------------------------------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/func/call.rs b/src/func/call.rs index b6881dd9..1dd171cd 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -1299,4 +1299,47 @@ impl Engine { .into()), } } + + /// Evaluate a text script in place - used primarily for 'eval'. + pub(crate) fn eval_script_expr_in_place( + &self, + scope: &mut Scope, + global: &mut GlobalRuntimeState, + state: &mut EvalState, + lib: &[&Module], + script: impl AsRef, + _pos: Position, + level: usize, + ) -> RhaiResult { + #[cfg(not(feature = "unchecked"))] + self.inc_operations(&mut global.num_operations, _pos)?; + + let script = script.as_ref().trim(); + if script.is_empty() { + return Ok(Dynamic::UNIT); + } + + // Compile the script text + // No optimizations because we only run it once + let ast = self.compile_with_scope_and_optimization_level( + &Scope::new(), + &[script], + #[cfg(not(feature = "no_optimize"))] + crate::OptimizationLevel::None, + )?; + + // If new functions are defined within the eval string, it is an error + #[cfg(not(feature = "no_function"))] + if !ast.shared_lib().is_empty() { + return Err(crate::PERR::WrongFnDefinition.into()); + } + + let statements = ast.statements(); + if statements.is_empty() { + return Ok(Dynamic::UNIT); + } + + // Evaluate the AST + self.eval_global_statements(scope, global, state, statements, lib, level) + } } diff --git a/src/func/script.rs b/src/func/script.rs index 02c08ad9..0ebb2e68 100644 --- a/src/func/script.rs +++ b/src/func/script.rs @@ -196,47 +196,4 @@ impl Engine { result } - - /// Evaluate a text script in place - used primarily for 'eval'. - pub(crate) fn eval_script_expr_in_place( - &self, - scope: &mut Scope, - global: &mut GlobalRuntimeState, - state: &mut EvalState, - lib: &[&Module], - script: impl AsRef, - _pos: Position, - level: usize, - ) -> RhaiResult { - #[cfg(not(feature = "unchecked"))] - self.inc_operations(&mut global.num_operations, _pos)?; - - let script = script.as_ref().trim(); - if script.is_empty() { - return Ok(Dynamic::UNIT); - } - - // Compile the script text - // No optimizations because we only run it once - let ast = self.compile_with_scope_and_optimization_level( - &Scope::new(), - &[script], - #[cfg(not(feature = "no_optimize"))] - crate::OptimizationLevel::None, - )?; - - // If new functions are defined within the eval string, it is an error - #[cfg(not(feature = "no_function"))] - if !ast.shared_lib().is_empty() { - return Err(crate::PERR::WrongFnDefinition.into()); - } - - let statements = ast.statements(); - if statements.is_empty() { - return Ok(Dynamic::UNIT); - } - - // Evaluate the AST - self.eval_global_statements(scope, global, state, statements, lib, level) - } }