diff --git a/src/api/call_fn.rs b/src/api/call_fn.rs index 1207c522..1a9e2347 100644 --- a/src/api/call_fn.rs +++ b/src/api/call_fn.rs @@ -260,7 +260,7 @@ impl Engine { ); let result = if eval_ast && !statements.is_empty() { - let r = self.eval_global_statements(scope, global, caches, statements, lib, 0); + let r = self.eval_global_statements(global, caches, lib, 0, scope, statements); if rewind_scope { scope.rewind(orig_scope_len); @@ -279,16 +279,16 @@ impl Engine { if let Some(fn_def) = ast.shared_lib().get_script_fn(name, args.len()) { self.call_script_fn( - scope, global, caches, lib, + 0, + scope, &mut this_ptr, fn_def, &mut args, rewind_scope, Position::NONE, - 0, ) } else { Err(ERR::ErrorFunctionNotFound(name.into(), Position::NONE).into()) @@ -306,7 +306,7 @@ impl Engine { if self.debugger.is_some() { global.debugger.status = crate::eval::DebuggerStatus::Terminate; let node = &crate::ast::Stmt::Noop(Position::NONE); - self.run_debugger(scope, global, lib, &mut this_ptr, node, 0)?; + self.run_debugger(global, caches, lib, 0, scope, &mut this_ptr, node)?; } Ok(result) diff --git a/src/api/eval.rs b/src/api/eval.rs index 3f37264d..ffef8623 100644 --- a/src/api/eval.rs +++ b/src/api/eval.rs @@ -186,8 +186,9 @@ impl Engine { ast: &AST, ) -> RhaiResultOf { let global = &mut GlobalRuntimeState::new(self); + let caches = &mut Caches::new(); - let result = self.eval_ast_with_scope_raw(scope, global, ast, 0)?; + let result = self.eval_ast_with_scope_raw(global, caches, 0, scope, ast)?; #[cfg(feature = "debugging")] if self.debugger.is_some() { @@ -197,7 +198,7 @@ impl Engine { ast.as_ref(), ]; let node = &crate::ast::Stmt::Noop(Position::NONE); - self.run_debugger(scope, global, lib, &mut None, node, 0)?; + self.run_debugger(global, caches, lib, 0, scope, &mut None, node)?; } let typ = self.map_type_name(result.type_name()); @@ -211,12 +212,12 @@ impl Engine { #[inline] pub(crate) fn eval_ast_with_scope_raw<'a>( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, - ast: &'a AST, + caches: &mut Caches, level: usize, + scope: &mut Scope, + ast: &'a AST, ) -> RhaiResult { - let mut caches = Caches::new(); global.source = ast.source_raw().cloned(); #[cfg(not(feature = "no_module"))] @@ -240,8 +241,7 @@ impl Engine { _lib = &[]; } - let result = - self.eval_global_statements(scope, global, &mut caches, statements, _lib, level); + let result = self.eval_global_statements(global, caches, _lib, level, scope, statements); #[cfg(not(feature = "no_module"))] { @@ -262,14 +262,14 @@ impl Engine { #[inline(always)] pub fn eval_statements_raw( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, caches: &mut Caches, - statements: &[crate::ast::Stmt], lib: &[&crate::Module], level: usize, + scope: &mut Scope, + statements: &[crate::ast::Stmt], ) -> RhaiResult { - self.eval_global_statements(scope, global, caches, statements, lib, level) + self.eval_global_statements(global, caches, lib, level, scope, statements) } } diff --git a/src/api/run.rs b/src/api/run.rs index e32136e6..effdd4b6 100644 --- a/src/api/run.rs +++ b/src/api/run.rs @@ -131,7 +131,7 @@ impl Engine { } else { &lib }; - self.eval_global_statements(scope, global, caches, statements, lib, 0)?; + self.eval_global_statements(global, caches, lib, 0, scope, statements)?; } #[cfg(feature = "debugging")] @@ -142,7 +142,7 @@ impl Engine { ast.as_ref(), ]; let node = &crate::ast::Stmt::Noop(crate::Position::NONE); - self.run_debugger(scope, global, lib, &mut None, node, 0)?; + self.run_debugger(global, caches, lib, 0, scope, &mut None, node)?; } Ok(()) diff --git a/src/eval/chaining.rs b/src/eval/chaining.rs index e7e1e754..ecc40fc7 100644 --- a/src/eval/chaining.rs +++ b/src/eval/chaining.rs @@ -41,6 +41,7 @@ impl Engine { global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, this_ptr: &mut Option<&mut Dynamic>, target: &mut Target, root: (&str, Position), @@ -49,7 +50,6 @@ impl Engine { rhs: &Expr, idx_values: &mut FnArgsVec, chain_type: ChainType, - level: usize, new_val: &mut Option<(Dynamic, &OpAssignment)>, ) -> RhaiResultOf<(Dynamic, bool)> { let is_ref_mut = target.is_ref(); @@ -73,7 +73,7 @@ impl Engine { if !parent_options.contains(ASTFlags::BREAK) => { #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, _parent, level)?; + self.run_debugger(global, caches, lib, level, scope, this_ptr, _parent)?; let idx_val = &mut idx_values.pop().unwrap(); let mut idx_val_for_setter = idx_val.clone(); @@ -82,14 +82,14 @@ impl Engine { let (try_setter, result) = { let mut obj = self.get_indexed_mut( - global, caches, lib, target, idx_val, idx_pos, false, true, level, + global, caches, lib, level, target, idx_val, idx_pos, false, true, )?; let is_obj_temp_val = obj.is_temp_value(); let obj_ptr = &mut obj; match self.eval_dot_index_chain_helper( - global, caches, lib, this_ptr, obj_ptr, root, rhs, *options, - &x.rhs, idx_values, rhs_chain, level, new_val, + global, caches, lib, level, this_ptr, obj_ptr, root, rhs, *options, + &x.rhs, idx_values, rhs_chain, new_val, ) { Ok((result, true)) if is_obj_temp_val => { (Some(obj.take_or_clone()), (result, true)) @@ -104,7 +104,7 @@ impl Engine { let idx = &mut idx_val_for_setter; let new_val = &mut new_val; self.call_indexer_set( - global, caches, lib, target, idx, new_val, is_ref_mut, level, + global, caches, lib, level, target, idx, new_val, is_ref_mut, ) .or_else(|e| match *e { ERR::ErrorIndexingType(..) => Ok((Dynamic::UNIT, false)), @@ -117,19 +117,19 @@ impl Engine { // xxx[rhs] op= new_val _ if new_val.is_some() => { #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, _parent, level)?; + self.run_debugger(global, caches, lib, level, scope, this_ptr, _parent)?; let (new_val, op_info) = new_val.take().expect("`Some`"); let idx_val = &mut idx_values.pop().unwrap(); let idx = &mut idx_val.clone(); let try_setter = match self.get_indexed_mut( - global, caches, lib, target, idx, pos, true, false, level, + global, caches, lib, level, target, idx, pos, true, false, ) { // Indexed value is not a temp value - update directly Ok(ref mut obj_ptr) => { self.eval_op_assignment( - global, caches, lib, op_info, obj_ptr, root, new_val, level, + global, caches, lib, level, op_info, obj_ptr, root, new_val, )?; self.check_data_size(obj_ptr, op_info.pos)?; None @@ -148,13 +148,13 @@ impl Engine { // Call the index getter to get the current value if let Ok(val) = - self.call_indexer_get(global, caches, lib, target, idx, level) + self.call_indexer_get(global, caches, lib, level, target, idx) { let mut val = val.into(); // Run the op-assignment self.eval_op_assignment( - global, caches, lib, op_info, &mut val, root, new_val, - level, + global, caches, lib, level, op_info, &mut val, root, + new_val, )?; // Replace new value new_val = val.take_or_clone(); @@ -166,7 +166,7 @@ impl Engine { let new_val = &mut new_val; self.call_indexer_set( - global, caches, lib, target, idx_val, new_val, is_ref_mut, level, + global, caches, lib, level, target, idx_val, new_val, is_ref_mut, )?; } @@ -175,12 +175,12 @@ impl Engine { // xxx[rhs] _ => { #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, _parent, level)?; + self.run_debugger(global, caches, lib, level, scope, this_ptr, _parent)?; let idx_val = &mut idx_values.pop().unwrap(); self.get_indexed_mut( - global, caches, lib, target, idx_val, pos, false, true, level, + global, caches, lib, level, target, idx_val, pos, false, true, ) .map(|v| (v.take_or_clone(), false)) } @@ -198,8 +198,9 @@ impl Engine { // xxx.fn_name(arg_expr_list) Expr::MethodCall(x, pos) if !x.is_qualified() && new_val.is_none() => { #[cfg(feature = "debugging")] - let reset_debugger = - self.run_debugger_with_reset(scope, global, lib, this_ptr, rhs, level)?; + let reset_debugger = self.run_debugger_with_reset( + global, caches, lib, level, scope, this_ptr, rhs, + )?; let crate::ast::FnCallExpr { name, hashes, args, .. @@ -210,8 +211,8 @@ impl Engine { let pos1 = args.get(0).map_or(Position::NONE, Expr::position); let result = self.make_method_call( - global, caches, lib, name, *hashes, target, call_args, pos1, *pos, - level, + global, caches, lib, level, name, *hashes, target, call_args, pos1, + *pos, ); idx_values.truncate(offset); @@ -232,16 +233,16 @@ impl Engine { // {xxx:map}.id op= ??? Expr::Property(x, pos) if target.is::() && new_val.is_some() => { #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, rhs, level)?; + self.run_debugger(global, caches, lib, level, scope, this_ptr, rhs)?; let index = &mut x.2.clone().into(); let (new_val, op_info) = new_val.take().expect("`Some`"); { let val_target = &mut self.get_indexed_mut( - global, caches, lib, target, index, *pos, true, false, level, + global, caches, lib, level, target, index, *pos, true, false, )?; self.eval_op_assignment( - global, caches, lib, op_info, val_target, root, new_val, level, + global, caches, lib, level, op_info, val_target, root, new_val, )?; } self.check_data_size(target.source(), op_info.pos)?; @@ -250,18 +251,18 @@ impl Engine { // {xxx:map}.id Expr::Property(x, pos) if target.is::() => { #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, rhs, level)?; + self.run_debugger(global, caches, lib, level, scope, this_ptr, rhs)?; let index = &mut x.2.clone().into(); let val = self.get_indexed_mut( - global, caches, lib, target, index, *pos, false, false, level, + global, caches, lib, level, target, index, *pos, false, false, )?; Ok((val.take_or_clone(), false)) } // xxx.id op= ??? Expr::Property(x, pos) if new_val.is_some() => { #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, rhs, level)?; + self.run_debugger(global, caches, lib, level, scope, this_ptr, rhs)?; let ((getter, hash_get), (setter, hash_set), name) = &**x; let (mut new_val, op_info) = new_val.take().expect("`Some`"); @@ -270,15 +271,15 @@ impl Engine { let args = &mut [target.as_mut()]; let (mut orig_val, ..) = self .exec_native_fn_call( - global, caches, lib, getter, None, *hash_get, args, is_ref_mut, - *pos, level, + global, caches, lib, level, getter, None, *hash_get, args, + is_ref_mut, *pos, ) .or_else(|err| match *err { // Try an indexer if property does not exist ERR::ErrorDotExpr(..) => { let mut prop = name.into(); self.call_indexer_get( - global, caches, lib, target, &mut prop, level, + global, caches, lib, level, target, &mut prop, ) .map(|r| (r, false)) .map_err(|e| { @@ -295,7 +296,7 @@ impl Engine { let orig_val = &mut (&mut orig_val).into(); self.eval_op_assignment( - global, caches, lib, op_info, orig_val, root, new_val, level, + global, caches, lib, level, op_info, orig_val, root, new_val, )?; } @@ -304,8 +305,8 @@ impl Engine { let args = &mut [target.as_mut(), &mut new_val]; self.exec_native_fn_call( - global, caches, lib, setter, None, *hash_set, args, is_ref_mut, *pos, - level, + global, caches, lib, level, setter, None, *hash_set, args, is_ref_mut, + *pos, ) .or_else(|err| match *err { // Try an indexer if property does not exist @@ -313,7 +314,7 @@ impl Engine { let idx = &mut name.into(); let new_val = &mut new_val; self.call_indexer_set( - global, caches, lib, target, idx, new_val, is_ref_mut, level, + global, caches, lib, level, target, idx, new_val, is_ref_mut, ) .map_err(|e| match *e { ERR::ErrorIndexingType(..) => err, @@ -326,13 +327,13 @@ impl Engine { // xxx.id Expr::Property(x, pos) => { #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, rhs, level)?; + self.run_debugger(global, caches, lib, level, scope, this_ptr, rhs)?; let ((getter, hash_get), _, name) = &**x; let args = &mut [target.as_mut()]; self.exec_native_fn_call( - global, caches, lib, getter, None, *hash_get, args, is_ref_mut, *pos, - level, + global, caches, lib, level, getter, None, *hash_get, args, is_ref_mut, + *pos, ) .map_or_else( |err| match *err { @@ -340,7 +341,7 @@ impl Engine { ERR::ErrorDotExpr(..) => { let mut prop = name.into(); self.call_indexer_get( - global, caches, lib, target, &mut prop, level, + global, caches, lib, level, target, &mut prop, ) .map(|r| (r, false)) .map_err(|e| match *e { @@ -363,18 +364,20 @@ impl Engine { let val_target = &mut match x.lhs { Expr::Property(ref p, pos) => { #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, _node, level)?; + self.run_debugger( + global, caches, lib, level, scope, this_ptr, _node, + )?; let index = &mut p.2.clone().into(); self.get_indexed_mut( - global, caches, lib, target, index, pos, false, true, level, + global, caches, lib, level, target, index, pos, false, true, )? } // {xxx:map}.fn_name(arg_expr_list)[expr] | {xxx:map}.fn_name(arg_expr_list).expr Expr::MethodCall(ref x, pos) if !x.is_qualified() => { #[cfg(feature = "debugging")] let reset_debugger = self.run_debugger_with_reset( - scope, global, lib, this_ptr, _node, level, + global, caches, lib, level, scope, this_ptr, _node, )?; let crate::ast::FnCallExpr { @@ -386,8 +389,8 @@ impl Engine { let pos1 = args.get(0).map_or(Position::NONE, Expr::position); let result = self.make_method_call( - global, caches, lib, name, *hashes, target, call_args, pos1, - pos, level, + global, caches, lib, level, name, *hashes, target, call_args, + pos1, pos, ); idx_values.truncate(offset); @@ -407,8 +410,8 @@ impl Engine { let rhs_chain = rhs.into(); self.eval_dot_index_chain_helper( - global, caches, lib, this_ptr, val_target, root, rhs, *options, &x.rhs, - idx_values, rhs_chain, level, new_val, + global, caches, lib, level, this_ptr, val_target, root, rhs, *options, + &x.rhs, idx_values, rhs_chain, new_val, ) .map_err(|err| err.fill_position(*x_pos)) } @@ -420,7 +423,9 @@ impl Engine { // xxx.prop[expr] | xxx.prop.expr Expr::Property(ref p, pos) => { #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, _node, level)?; + self.run_debugger( + global, caches, lib, level, scope, this_ptr, _node, + )?; let ((getter, hash_get), (setter, hash_set), name) = &**p; let rhs_chain = rhs.into(); @@ -430,15 +435,15 @@ impl Engine { // Assume getters are always pure let (mut val, ..) = self .exec_native_fn_call( - global, caches, lib, getter, None, *hash_get, args, - is_ref_mut, pos, level, + global, caches, lib, level, getter, None, *hash_get, args, + is_ref_mut, pos, ) .or_else(|err| match *err { // Try an indexer if property does not exist ERR::ErrorDotExpr(..) => { let mut prop = name.into(); self.call_indexer_get( - global, caches, lib, target, &mut prop, level, + global, caches, lib, level, target, &mut prop, ) .map(|r| (r, false)) .map_err( @@ -455,8 +460,8 @@ impl Engine { let (result, may_be_changed) = self .eval_dot_index_chain_helper( - global, caches, lib, this_ptr, val, root, rhs, *options, - &x.rhs, idx_values, rhs_chain, level, new_val, + global, caches, lib, level, this_ptr, val, root, rhs, + *options, &x.rhs, idx_values, rhs_chain, new_val, ) .map_err(|err| err.fill_position(*x_pos))?; @@ -466,8 +471,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, None, *hash_set, args, - is_ref_mut, pos, level, + global, caches, lib, level, setter, None, *hash_set, args, + is_ref_mut, pos, ) .or_else( |err| match *err { @@ -476,8 +481,8 @@ impl Engine { let idx = &mut name.into(); let new_val = val; self.call_indexer_set( - global, caches, lib, target, idx, new_val, - is_ref_mut, level, + global, caches, lib, level, target, idx, + new_val, is_ref_mut, ) .or_else(|e| match *e { // If there is no setter, no need to feed it @@ -499,7 +504,7 @@ impl Engine { Expr::MethodCall(ref f, pos) if !f.is_qualified() => { #[cfg(feature = "debugging")] let reset_debugger = self.run_debugger_with_reset( - scope, global, lib, this_ptr, _node, level, + global, caches, lib, level, scope, this_ptr, _node, )?; let crate::ast::FnCallExpr { @@ -512,8 +517,8 @@ impl Engine { let pos1 = args.get(0).map_or(Position::NONE, Expr::position); let result = self.make_method_call( - global, caches, lib, name, *hashes, target, call_args, pos1, - pos, level, + global, caches, lib, level, name, *hashes, target, call_args, + pos1, pos, ); idx_values.truncate(offset); @@ -525,8 +530,8 @@ impl Engine { let val = &mut val.into(); self.eval_dot_index_chain_helper( - global, caches, lib, this_ptr, val, root, rhs, *options, - &x.rhs, idx_values, rhs_chain, level, new_val, + global, caches, lib, level, this_ptr, val, root, rhs, *options, + &x.rhs, idx_values, rhs_chain, new_val, ) .map_err(|err| err.fill_position(pos)) } @@ -548,13 +553,13 @@ impl Engine { /// Evaluate a dot/index chain. pub(crate) fn eval_dot_index_chain( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, expr: &Expr, - level: usize, new_val: &mut Option<(Dynamic, &OpAssignment)>, ) -> RhaiResult { let chain_type = ChainType::from(expr); @@ -592,8 +597,8 @@ impl Engine { // All other patterns - evaluate the arguments chain _ => { self.eval_dot_index_chain_arguments( - scope, global, caches, lib, this_ptr, rhs, options, chain_type, idx_values, - level, + global, caches, lib, level, scope, this_ptr, rhs, options, chain_type, + idx_values, )?; } } @@ -602,18 +607,18 @@ impl Engine { // id.??? or id[???] Expr::Variable(x, .., var_pos) => { #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, lhs, level)?; + self.run_debugger(global, caches, lib, level, scope, this_ptr, lhs)?; self.track_operation(global, *var_pos)?; let (mut target, ..) = - self.search_namespace(scope, global, lib, this_ptr, lhs, level)?; + self.search_namespace(global, caches, lib, level, scope, this_ptr, lhs)?; let obj_ptr = &mut target; let root = (x.3.as_str(), *var_pos); self.eval_dot_index_chain_helper( - global, caches, lib, &mut None, obj_ptr, root, expr, options, rhs, idx_values, - chain_type, level, new_val, + global, caches, lib, level, &mut None, obj_ptr, root, expr, options, rhs, + idx_values, chain_type, new_val, ) } // {expr}.??? = ??? or {expr}[???] = ??? @@ -621,14 +626,14 @@ impl Engine { // {expr}.??? or {expr}[???] expr => { let value = self - .eval_expr(scope, global, caches, lib, this_ptr, expr, level)? + .eval_expr(global, caches, lib, level, scope, this_ptr, expr)? .flatten(); let obj_ptr = &mut value.into(); let root = ("", expr.start_position()); self.eval_dot_index_chain_helper( - global, caches, lib, this_ptr, obj_ptr, root, expr, options, rhs, idx_values, - chain_type, level, new_val, + global, caches, lib, level, this_ptr, obj_ptr, root, expr, options, rhs, + idx_values, chain_type, new_val, ) } } @@ -639,16 +644,16 @@ impl Engine { /// Evaluate a chain of indexes and store the results in a [`FnArgsVec`]. fn eval_dot_index_chain_arguments( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, expr: &Expr, parent_options: ASTFlags, parent_chain_type: ChainType, idx_values: &mut FnArgsVec, - level: usize, ) -> RhaiResultOf<()> { self.track_operation(global, expr.position())?; @@ -659,7 +664,7 @@ impl Engine { { for arg_expr in &x.args { idx_values.push( - self.get_arg_value(scope, global, caches, lib, this_ptr, arg_expr, level)? + self.get_arg_value(global, caches, lib, level, scope, this_ptr, arg_expr)? .0 .flatten(), ); @@ -694,7 +699,7 @@ impl Engine { for arg_expr in &x.args { _arg_values.push( self.get_arg_value( - scope, global, caches, lib, this_ptr, arg_expr, level, + global, caches, lib, level, scope, this_ptr, arg_expr, )? .0 .flatten(), @@ -712,7 +717,7 @@ impl Engine { #[cfg(not(feature = "no_index"))] _ if parent_chain_type == ChainType::Indexing => { _arg_values.push( - self.eval_expr(scope, global, caches, lib, this_ptr, lhs, level)? + self.eval_expr(global, caches, lib, level, scope, this_ptr, lhs)? .flatten(), ); } @@ -723,8 +728,8 @@ impl Engine { let chain_type = expr.into(); self.eval_dot_index_chain_arguments( - scope, global, caches, lib, this_ptr, rhs, *options, chain_type, idx_values, - level, + global, caches, lib, level, scope, this_ptr, rhs, *options, chain_type, + idx_values, )?; if !_arg_values.is_empty() { @@ -738,7 +743,7 @@ impl Engine { } #[cfg(not(feature = "no_index"))] _ if parent_chain_type == ChainType::Indexing => idx_values.push( - self.eval_expr(scope, global, caches, lib, this_ptr, expr, level)? + self.eval_expr(global, caches, lib, level, scope, this_ptr, expr)? .flatten(), ), _ => unreachable!("unknown chained expression: {:?}", expr), @@ -754,9 +759,9 @@ impl Engine { global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, target: &mut Dynamic, idx: &mut Dynamic, - level: usize, ) -> RhaiResultOf { let args = &mut [target, idx]; let hash = global.hash_idx_get(); @@ -765,7 +770,7 @@ impl Engine { let level = level + 1; self.exec_native_fn_call( - global, caches, lib, fn_name, None, hash, args, true, pos, level, + global, caches, lib, level, fn_name, None, hash, args, true, pos, ) .map(|(r, ..)| r) } @@ -777,11 +782,11 @@ impl Engine { global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, target: &mut Dynamic, idx: &mut Dynamic, new_val: &mut Dynamic, is_ref_mut: bool, - level: usize, ) -> RhaiResultOf<(Dynamic, bool)> { let hash = global.hash_idx_set(); let args = &mut [target, idx, new_val]; @@ -790,7 +795,7 @@ impl Engine { let level = level + 1; self.exec_native_fn_call( - global, caches, lib, fn_name, None, hash, args, is_ref_mut, pos, level, + global, caches, lib, level, fn_name, None, hash, args, is_ref_mut, pos, ) } @@ -801,12 +806,12 @@ impl Engine { global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, target: &'t mut Dynamic, idx: &mut Dynamic, idx_pos: Position, _add_if_not_found: bool, use_indexers: bool, - level: usize, ) -> RhaiResultOf> { self.track_operation(global, Position::NONE)?; @@ -1010,7 +1015,7 @@ impl Engine { } _ if use_indexers => self - .call_indexer_get(global, caches, lib, target, idx, level) + .call_indexer_get(global, caches, lib, level, target, idx) .map(Into::into), _ => Err(ERR::ErrorIndexingType( diff --git a/src/eval/debugger.rs b/src/eval/debugger.rs index 2ddf0991..9b516fdf 100644 --- a/src/eval/debugger.rs +++ b/src/eval/debugger.rs @@ -1,7 +1,7 @@ //! Module defining the debugging interface. #![cfg(feature = "debugging")] -use super::{EvalContext, GlobalRuntimeState}; +use super::{Caches, EvalContext, GlobalRuntimeState}; use crate::ast::{ASTNode, Expr, Stmt}; use crate::{ Dynamic, Engine, EvalAltResult, ImmutableString, Module, Position, RhaiResultOf, Scope, @@ -411,16 +411,17 @@ impl Engine { #[inline(always)] pub(crate) fn run_debugger<'a>( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, + caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, node: impl Into>, - level: usize, ) -> RhaiResultOf<()> { if self.debugger.is_some() { if let Some(cmd) = - self.run_debugger_with_reset_raw(scope, global, lib, this_ptr, node, level)? + self.run_debugger_with_reset_raw(global, caches, lib, level, scope, this_ptr, node)? { global.debugger.status = cmd; } @@ -437,15 +438,16 @@ impl Engine { #[inline(always)] pub(crate) fn run_debugger_with_reset<'a>( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, + caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, node: impl Into>, - level: usize, ) -> RhaiResultOf> { if self.debugger.is_some() { - self.run_debugger_with_reset_raw(scope, global, lib, this_ptr, node, level) + self.run_debugger_with_reset_raw(global, caches, lib, level, scope, this_ptr, node) } else { Ok(None) } @@ -459,12 +461,13 @@ impl Engine { #[inline] pub(crate) fn run_debugger_with_reset_raw<'a>( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, + caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, node: impl Into>, - level: usize, ) -> RhaiResultOf> { let node = node.into(); @@ -494,7 +497,7 @@ impl Engine { }, }; - self.run_debugger_raw(scope, global, lib, this_ptr, node, event, level) + self.run_debugger_raw(global, caches, lib, level, scope, this_ptr, node, event) } /// Run the debugger callback unconditionally. /// @@ -505,17 +508,19 @@ impl Engine { #[inline] pub(crate) fn run_debugger_raw<'a>( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, + caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, node: ASTNode<'a>, event: DebuggerEvent, - level: usize, ) -> Result, Box> { let src = global.source_raw().cloned(); let src = src.as_ref().map(|s| s.as_str()); - let context = crate::EvalContext::new(self, scope, global, None, lib, this_ptr, level); + let context = + crate::EvalContext::new(self, global, Some(caches), lib, level, scope, this_ptr); if let Some((.., ref on_debugger)) = self.debugger { let command = on_debugger(context, event, node, src, node.position())?; diff --git a/src/eval/eval_context.rs b/src/eval/eval_context.rs index b1185a39..172720cd 100644 --- a/src/eval/eval_context.rs +++ b/src/eval/eval_context.rs @@ -31,12 +31,12 @@ impl<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'pg, ' #[must_use] pub fn new( engine: &'a Engine, - scope: &'s mut Scope<'ps>, global: &'g mut GlobalRuntimeState<'pg>, caches: Option<&'c mut Caches<'pc>>, lib: &'a [&'a Module], - this_ptr: &'t mut Option<&'pt mut Dynamic>, level: usize, + scope: &'s mut Scope<'ps>, + this_ptr: &'t mut Option<&'pt mut Dynamic>, ) -> Self { Self { engine, @@ -182,23 +182,23 @@ impl<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'pg, ' match expr { crate::ast::Expr::Stmt(statements) => self.engine.eval_stmt_block( - self.scope, self.global, caches, self.lib, + self.level, + self.scope, self.this_ptr, statements, rewind_scope, - self.level, ), _ => self.engine.eval_expr( - self.scope, self.global, caches, self.lib, + self.level, + self.scope, self.this_ptr, expr, - self.level, ), } } diff --git a/src/eval/expr.rs b/src/eval/expr.rs index 521cb036..35da7117 100644 --- a/src/eval/expr.rs +++ b/src/eval/expr.rs @@ -49,25 +49,26 @@ impl Engine { /// depending on whether the variable name is namespace-qualified. pub(crate) fn search_namespace<'s>( &self, - scope: &'s mut Scope, global: &mut GlobalRuntimeState, + caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &'s mut Scope, this_ptr: &'s mut Option<&mut Dynamic>, expr: &Expr, - level: usize, ) -> RhaiResultOf<(Target<'s>, Position)> { match expr { Expr::Variable(_, Some(_), _) => { - self.search_scope_only(scope, global, lib, this_ptr, expr, level) + self.search_scope_only(global, caches, lib, level, scope, this_ptr, expr) } Expr::Variable(v, None, _var_pos) => match &**v { // Normal variable access #[cfg(not(feature = "no_module"))] (_, ns, ..) if ns.is_empty() => { - self.search_scope_only(scope, global, lib, this_ptr, expr, level) + self.search_scope_only(global, caches, lib, level, scope, this_ptr, expr) } #[cfg(feature = "no_module")] - (_, (), ..) => self.search_scope_only(scope, global, lib, this_ptr, expr, level), + (_, (), ..) => self.search_scope_only(scope, global, lib, this_ptr, expr), // Qualified variable access #[cfg(not(feature = "no_module"))] @@ -132,12 +133,13 @@ impl Engine { /// Panics if `expr` is not [`Expr::Variable`]. pub(crate) fn search_scope_only<'s>( &self, - scope: &'s mut Scope, global: &mut GlobalRuntimeState, + caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &'s mut Scope, this_ptr: &'s mut Option<&mut Dynamic>, expr: &Expr, - level: usize, ) -> RhaiResultOf<(Target<'s>, Position)> { // Make sure that the pointer indirection is taken only when absolutely necessary. @@ -169,7 +171,7 @@ impl Engine { // Check the variable resolver, if any if let Some(ref resolve_var) = self.resolve_var { - let context = EvalContext::new(self, scope, global, None, lib, this_ptr, level); + let context = EvalContext::new(self, global, Some(caches), lib, level, scope, this_ptr); let var_name = expr.get_variable_name(true).expect("`Expr::Variable`"); match resolve_var(var_name, index, context) { Ok(Some(mut result)) => { @@ -215,13 +217,13 @@ impl Engine { // Errors that are not recoverable, such as system errors or safety errors, can use `?`. pub(crate) fn eval_expr( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, expr: &Expr, - level: usize, ) -> RhaiResult { // Coded this way for better branch prediction. // Popular branches are lifted out of the `match` statement into their own branches. @@ -231,12 +233,12 @@ impl Engine { if let Expr::FnCall(x, pos) = expr { #[cfg(feature = "debugging")] let reset_debugger = - self.run_debugger_with_reset(scope, global, lib, this_ptr, expr, level)?; + self.run_debugger_with_reset(global, caches, lib, level, scope, this_ptr, expr)?; self.track_operation(global, expr.position())?; let result = - self.eval_fn_call_expr(scope, global, caches, lib, this_ptr, x, *pos, level); + self.eval_fn_call_expr(global, caches, lib, level, scope, this_ptr, x, *pos); #[cfg(feature = "debugging")] global.debugger.reset_status(reset_debugger); @@ -249,7 +251,7 @@ impl Engine { // will cost more than the mis-predicted `match` branch. if let Expr::Variable(x, index, var_pos) = expr { #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, expr, level)?; + self.run_debugger(global, caches, lib, level, scope, this_ptr, expr)?; self.track_operation(global, expr.position())?; @@ -259,14 +261,14 @@ impl Engine { .cloned() .ok_or_else(|| ERR::ErrorUnboundThis(*var_pos).into()) } else { - self.search_namespace(scope, global, lib, this_ptr, expr, level) + self.search_namespace(global, caches, lib, level, scope, this_ptr, expr) .map(|(val, ..)| val.take_or_clone()) }; } #[cfg(feature = "debugging")] let reset_debugger = - self.run_debugger_with_reset(scope, global, lib, this_ptr, expr, level)?; + self.run_debugger_with_reset(global, caches, lib, level, scope, this_ptr, expr)?; self.track_operation(global, expr.position())?; @@ -293,12 +295,12 @@ impl Engine { .iter() .try_for_each(|expr| { let item = - self.eval_expr(scope, global, caches, lib, this_ptr, expr, level)?; + self.eval_expr(global, caches, lib, level, scope, this_ptr, expr)?; op_info.pos = expr.start_position(); self.eval_op_assignment( - global, caches, lib, &op_info, target, root, item, level, + global, caches, lib, level, &op_info, target, root, item, ) }) .map(|_| concat.take_or_clone()); @@ -316,7 +318,7 @@ impl Engine { crate::Array::with_capacity(x.len()), |mut array, item_expr| { let value = self - .eval_expr(scope, global, caches, lib, this_ptr, item_expr, level)? + .eval_expr(global, caches, lib, level, scope, this_ptr, item_expr)? .flatten(); #[cfg(not(feature = "unchecked"))] @@ -348,7 +350,7 @@ impl Engine { x.0.iter() .try_fold(x.1.clone(), |mut map, (key, value_expr)| { let value = self - .eval_expr(scope, global, caches, lib, this_ptr, value_expr, level)? + .eval_expr(global, caches, lib, level, scope, this_ptr, value_expr)? .flatten(); #[cfg(not(feature = "unchecked"))] @@ -372,7 +374,7 @@ impl Engine { Expr::And(x, ..) => { let lhs = self - .eval_expr(scope, global, caches, lib, this_ptr, &x.lhs, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, &x.lhs) .and_then(|v| { v.as_bool().map_err(|typ| { self.make_type_mismatch_err::(typ, x.lhs.position()) @@ -381,7 +383,7 @@ impl Engine { match lhs { Ok(true) => self - .eval_expr(scope, global, caches, lib, this_ptr, &x.rhs, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, &x.rhs) .and_then(|v| { v.as_bool() .map_err(|typ| { @@ -395,7 +397,7 @@ impl Engine { Expr::Or(x, ..) => { let lhs = self - .eval_expr(scope, global, caches, lib, this_ptr, &x.lhs, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, &x.lhs) .and_then(|v| { v.as_bool().map_err(|typ| { self.make_type_mismatch_err::(typ, x.lhs.position()) @@ -404,7 +406,7 @@ impl Engine { match lhs { Ok(false) => self - .eval_expr(scope, global, caches, lib, this_ptr, &x.rhs, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, &x.rhs) .and_then(|v| { v.as_bool() .map_err(|typ| { @@ -417,11 +419,11 @@ impl Engine { } Expr::Coalesce(x, ..) => { - let lhs = self.eval_expr(scope, global, caches, lib, this_ptr, &x.lhs, level); + let lhs = self.eval_expr(global, caches, lib, level, scope, this_ptr, &x.lhs); match lhs { Ok(value) if value.is::<()>() => { - self.eval_expr(scope, global, caches, lib, this_ptr, &x.rhs, level) + self.eval_expr(global, caches, lib, level, scope, this_ptr, &x.rhs) } _ => lhs, } @@ -442,7 +444,7 @@ impl Engine { )) })?; let mut context = - EvalContext::new(self, scope, global, Some(caches), lib, this_ptr, level); + EvalContext::new(self, global, Some(caches), lib, level, scope, this_ptr); let result = (custom_def.func)(&mut context, &expressions, &custom.state); @@ -451,16 +453,16 @@ impl Engine { Expr::Stmt(x) if x.is_empty() => Ok(Dynamic::UNIT), Expr::Stmt(x) => { - self.eval_stmt_block(scope, global, caches, lib, this_ptr, x, true, level) + self.eval_stmt_block(global, caches, lib, level, scope, this_ptr, x, true) } #[cfg(not(feature = "no_index"))] Expr::Index(..) => self - .eval_dot_index_chain(scope, global, caches, lib, this_ptr, expr, level, &mut None), + .eval_dot_index_chain(global, caches, lib, level, scope, this_ptr, expr, &mut None), #[cfg(not(feature = "no_object"))] Expr::Dot(..) => self - .eval_dot_index_chain(scope, global, caches, lib, this_ptr, expr, level, &mut None), + .eval_dot_index_chain(global, caches, lib, level, scope, this_ptr, expr, &mut None), _ => unreachable!("expression cannot be evaluated: {:?}", expr), }; diff --git a/src/eval/stmt.rs b/src/eval/stmt.rs index f61749a8..5bf03093 100644 --- a/src/eval/stmt.rs +++ b/src/eval/stmt.rs @@ -25,14 +25,14 @@ impl Engine { // Errors that are not recoverable, such as system errors or safety errors, can use `?`. pub(crate) fn eval_stmt_block( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, statements: &[Stmt], restore_orig_state: bool, - level: usize, ) -> RhaiResult { if statements.is_empty() { return Ok(Dynamic::UNIT); @@ -53,14 +53,14 @@ impl Engine { let imports_len = global.num_imports(); let result = self.eval_stmt( - scope, global, caches, lib, + level, + scope, this_ptr, stmt, restore_orig_state, - level, )?; #[cfg(not(feature = "no_module"))] @@ -113,11 +113,11 @@ impl Engine { global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, op_info: &OpAssignment, target: &mut Target, root: (&str, Position), new_val: Dynamic, - level: usize, ) -> RhaiResultOf<()> { if target.is_read_only() { // Assignment to constant variable @@ -156,7 +156,7 @@ impl Engine { let token = Some(op_assign_token); match self.exec_native_fn_call( - global, caches, lib, op_assign, token, hash, args, true, *op_pos, level, + global, caches, lib, level, op_assign, token, hash, args, true, *op_pos, ) { Ok(_) => (), Err(err) if matches!(*err, ERR::ErrorFunctionNotFound(ref f, ..) if f.starts_with(op_assign)) => @@ -166,7 +166,7 @@ impl Engine { *args[0] = self .exec_native_fn_call( - global, caches, lib, op, token, *hash_op, args, true, *op_pos, level, + global, caches, lib, level, op, token, *hash_op, args, true, *op_pos, ) .map_err(|err| err.fill_position(op_info.pos))? .0 @@ -194,18 +194,18 @@ impl Engine { // Errors that are not recoverable, such as system errors or safety errors, can use `?`. pub(crate) fn eval_stmt( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, stmt: &Stmt, rewind_scope: bool, - level: usize, ) -> RhaiResult { #[cfg(feature = "debugging")] let reset_debugger = - self.run_debugger_with_reset(scope, global, lib, this_ptr, stmt, level)?; + self.run_debugger_with_reset(global, caches, lib, level, scope, this_ptr, stmt)?; // Coded this way for better branch prediction. // Popular branches are lifted out of the `match` statement into their own branches. @@ -215,7 +215,7 @@ impl Engine { self.track_operation(global, stmt.position())?; let result = - self.eval_fn_call_expr(scope, global, caches, lib, this_ptr, x, *pos, level); + self.eval_fn_call_expr(global, caches, lib, level, scope, this_ptr, x, *pos); #[cfg(feature = "debugging")] global.debugger.reset_status(reset_debugger); @@ -233,12 +233,12 @@ impl Engine { let result = if let Expr::Variable(x, ..) = lhs { let rhs_result = self - .eval_expr(scope, global, caches, lib, this_ptr, rhs, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, rhs) .map(Dynamic::flatten); if let Ok(rhs_val) = rhs_result { let search_result = - self.search_namespace(scope, global, lib, this_ptr, lhs, level); + self.search_namespace(global, caches, lib, level, scope, this_ptr, lhs); if let Ok(search_val) = search_result { let (mut lhs_ptr, pos) = search_val; @@ -265,7 +265,7 @@ impl Engine { let lhs_ptr = &mut lhs_ptr; self.eval_op_assignment( - global, caches, lib, op_info, lhs_ptr, root, rhs_val, level, + global, caches, lib, level, op_info, lhs_ptr, root, rhs_val, ) .map(|_| Dynamic::UNIT) } else { @@ -277,7 +277,7 @@ impl Engine { } else { let (op_info, BinaryExpr { lhs, rhs }) = &**x; - let rhs_result = self.eval_expr(scope, global, caches, lib, this_ptr, rhs, level); + let rhs_result = self.eval_expr(global, caches, lib, level, scope, this_ptr, rhs); if let Ok(rhs_val) = rhs_result { // Check if the result is a string. If so, intern it. @@ -307,14 +307,14 @@ impl Engine { #[cfg(not(feature = "no_index"))] Expr::Index(..) => self .eval_dot_index_chain( - scope, global, caches, lib, this_ptr, lhs, level, _new_val, + global, caches, lib, level, scope, this_ptr, lhs, _new_val, ) .map(|_| Dynamic::UNIT), // dot_lhs.dot_rhs op= rhs #[cfg(not(feature = "no_object"))] Expr::Dot(..) => self .eval_dot_index_chain( - scope, global, caches, lib, this_ptr, lhs, level, _new_val, + global, caches, lib, level, scope, this_ptr, lhs, _new_val, ) .map(|_| Dynamic::UNIT), _ => unreachable!("cannot assign to expression: {:?}", lhs), @@ -338,13 +338,13 @@ impl Engine { // Expression as statement Stmt::Expr(expr) => self - .eval_expr(scope, global, caches, lib, this_ptr, expr, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, expr) .map(Dynamic::flatten), // Block scope Stmt::Block(statements, ..) if statements.is_empty() => Ok(Dynamic::UNIT), Stmt::Block(statements, ..) => self.eval_stmt_block( - scope, global, caches, lib, this_ptr, statements, true, level, + global, caches, lib, level, scope, this_ptr, statements, true, ), // If statement @@ -352,7 +352,7 @@ impl Engine { let (expr, if_block, else_block) = &**x; let guard_val = self - .eval_expr(scope, global, caches, lib, this_ptr, expr, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, expr) .and_then(|v| { v.as_bool().map_err(|typ| { self.make_type_mismatch_err::(typ, expr.position()) @@ -362,11 +362,11 @@ impl Engine { match guard_val { Ok(true) if if_block.is_empty() => Ok(Dynamic::UNIT), Ok(true) => self.eval_stmt_block( - scope, global, caches, lib, this_ptr, if_block, true, level, + global, caches, lib, level, scope, this_ptr, if_block, true, ), Ok(false) if else_block.is_empty() => Ok(Dynamic::UNIT), Ok(false) => self.eval_stmt_block( - scope, global, caches, lib, this_ptr, else_block, true, level, + global, caches, lib, level, scope, this_ptr, else_block, true, ), err => err.map(Into::into), } @@ -385,7 +385,7 @@ impl Engine { ) = &**x; let value_result = - self.eval_expr(scope, global, caches, lib, this_ptr, expr, level); + self.eval_expr(global, caches, lib, level, scope, this_ptr, expr); if let Ok(value) = value_result { let expr_result = if value.is_hashable() { @@ -405,7 +405,7 @@ impl Engine { let cond_result = match block.condition { Expr::BoolConstant(b, ..) => Ok(b), ref c => self - .eval_expr(scope, global, caches, lib, this_ptr, c, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, c) .and_then(|v| { v.as_bool().map_err(|typ| { self.make_type_mismatch_err::( @@ -436,7 +436,7 @@ impl Engine { let cond_result = match block.condition { Expr::BoolConstant(b, ..) => Ok(b), ref c => self - .eval_expr(scope, global, caches, lib, this_ptr, c, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, c) .and_then(|v| { v.as_bool().map_err(|typ| { self.make_type_mismatch_err::( @@ -466,12 +466,12 @@ impl Engine { }; if let Ok(Some(expr)) = expr_result { - self.eval_expr(scope, global, caches, lib, this_ptr, expr, level) + self.eval_expr(global, caches, lib, level, scope, this_ptr, expr) } else if let Ok(None) = expr_result { // Default match clause def_case.as_ref().map_or(Ok(Dynamic::UNIT), |&index| { let def_expr = &expressions[index].expr; - self.eval_expr(scope, global, caches, lib, this_ptr, def_expr, level) + self.eval_expr(global, caches, lib, level, scope, this_ptr, def_expr) }) } else { expr_result.map(|_| Dynamic::UNIT) @@ -492,7 +492,7 @@ impl Engine { } else { loop { match self.eval_stmt_block( - scope, global, caches, lib, this_ptr, body, true, level, + global, caches, lib, level, scope, this_ptr, body, true, ) { Ok(_) => (), Err(err) => match *err { @@ -511,7 +511,7 @@ impl Engine { loop { let condition = self - .eval_expr(scope, global, caches, lib, this_ptr, expr, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, expr) .and_then(|v| { v.as_bool().map_err(|typ| { self.make_type_mismatch_err::(typ, expr.position()) @@ -523,7 +523,7 @@ impl Engine { Ok(true) if body.is_empty() => (), Ok(true) => { match self.eval_stmt_block( - scope, global, caches, lib, this_ptr, body, true, level, + global, caches, lib, level, scope, this_ptr, body, true, ) { Ok(_) => (), Err(err) => match *err { @@ -546,7 +546,7 @@ impl Engine { loop { if !body.is_empty() { match self.eval_stmt_block( - scope, global, caches, lib, this_ptr, body, true, level, + global, caches, lib, level, scope, this_ptr, body, true, ) { Ok(_) => (), Err(err) => match *err { @@ -558,7 +558,7 @@ impl Engine { } let condition = self - .eval_expr(scope, global, caches, lib, this_ptr, expr, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, expr) .and_then(|v| { v.as_bool().map_err(|typ| { self.make_type_mismatch_err::(typ, expr.position()) @@ -578,7 +578,7 @@ impl Engine { let (var_name, counter, expr, statements) = &**x; let iter_result = self - .eval_expr(scope, global, caches, lib, this_ptr, expr, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, expr) .map(Dynamic::flatten); if let Ok(iter_obj) = iter_result { @@ -652,7 +652,7 @@ impl Engine { } self.eval_stmt_block( - scope, global, caches, lib, this_ptr, statements, true, level, + global, caches, lib, level, scope, this_ptr, statements, true, ) .map(|_| Dynamic::UNIT) .or_else(|err| match *err { @@ -681,7 +681,7 @@ impl Engine { let is_break = options.contains(ASTFlags::BREAK); if let Some(ref expr) = expr { - self.eval_expr(scope, global, caches, lib, this_ptr, expr, level) + self.eval_expr(global, caches, lib, level, scope, this_ptr, expr) .and_then(|v| ERR::LoopBreak(is_break, v, *pos).into()) } else { Err(ERR::LoopBreak(is_break, Dynamic::UNIT, *pos).into()) @@ -700,7 +700,7 @@ impl Engine { } = &**x; let result = self - .eval_stmt_block(scope, global, caches, lib, this_ptr, try_block, true, level) + .eval_stmt_block(global, caches, lib, level, scope, this_ptr, try_block, true) .map(|_| Dynamic::UNIT); match result { @@ -750,14 +750,14 @@ impl Engine { } let result = self.eval_stmt_block( - scope, global, caches, lib, + level, + scope, this_ptr, catch_block, true, - level, ); scope.rewind(orig_scope_len); @@ -779,7 +779,7 @@ impl Engine { // Throw value Stmt::Return(Some(expr), options, pos) if options.contains(ASTFlags::BREAK) => self - .eval_expr(scope, global, caches, lib, this_ptr, expr, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, expr) .and_then(|v| Err(ERR::ErrorRuntime(v.flatten(), *pos).into())), // Empty throw @@ -789,7 +789,7 @@ impl Engine { // Return value Stmt::Return(Some(expr), .., pos) => self - .eval_expr(scope, global, caches, lib, this_ptr, expr, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, expr) .and_then(|v| Err(ERR::Return(v.flatten(), *pos).into())), // Empty return @@ -821,7 +821,7 @@ impl Engine { nesting_level, will_shadow, }; - let context = EvalContext::new(self, scope, global, None, lib, this_ptr, level); + let context = EvalContext::new(self, global, None, lib, level, scope, this_ptr); match filter(true, info, context) { Ok(true) => None, @@ -841,7 +841,7 @@ impl Engine { } else { // Evaluate initial value let value_result = self - .eval_expr(scope, global, caches, lib, this_ptr, expr, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, expr) .map(Dynamic::flatten); if let Ok(mut value) = value_result { @@ -904,7 +904,7 @@ impl Engine { } let path_result = self - .eval_expr(scope, global, caches, lib, this_ptr, expr, level) + .eval_expr(global, caches, lib, level, scope, this_ptr, expr) .and_then(|v| { let typ = v.type_name(); v.try_cast::().ok_or_else(|| { @@ -1016,15 +1016,15 @@ impl Engine { #[inline] pub(crate) fn eval_global_statements( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, caches: &mut Caches, - statements: &[Stmt], lib: &[&Module], level: usize, + scope: &mut Scope, + statements: &[Stmt], ) -> RhaiResult { self.eval_stmt_block( - scope, global, caches, lib, &mut None, statements, false, level, + global, caches, lib, level, scope, &mut None, statements, false, ) .or_else(|err| match *err { ERR::Return(out, ..) => Ok(out), diff --git a/src/func/call.rs b/src/func/call.rs index da03b7c9..6677ab32 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -326,13 +326,13 @@ impl Engine { global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, name: &str, op_token: Option<&Token>, hash: u64, args: &mut FnCallArgs, is_ref_mut: bool, pos: Position, - level: usize, ) -> RhaiResultOf<(Dynamic, bool)> { self.track_operation(global, pos)?; @@ -416,7 +416,9 @@ impl Engine { Ok(ref r) => crate::eval::DebuggerEvent::FunctionExitWithValue(r), Err(ref err) => crate::eval::DebuggerEvent::FunctionExitWithError(err), }; - match self.run_debugger_raw(scope, global, lib, &mut None, node, event, level) { + match self + .run_debugger_raw(global, caches, lib, level, scope, &mut None, node, event) + { Ok(_) => (), Err(err) => _result = Err(err), } @@ -536,10 +538,11 @@ impl Engine { /// all others are silently replaced by `()`! pub(crate) fn exec_fn_call( &self, - _scope: Option<&mut Scope>, global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, + _scope: Option<&mut Scope>, fn_name: &str, op_token: Option<&Token>, hashes: FnCallHashes, @@ -547,7 +550,6 @@ impl Engine { is_ref_mut: bool, _is_method_call: bool, pos: Position, - level: usize, ) -> RhaiResultOf<(Dynamic, bool)> { fn no_method_err(name: &str, pos: Position) -> RhaiResultOf<(Dynamic, bool)> { Err(ERR::ErrorRuntime( @@ -654,16 +656,16 @@ impl Engine { let (first_arg, rest_args) = args.split_first_mut().unwrap(); self.call_script_fn( - scope, global, caches, lib, + level, + scope, &mut Some(*first_arg), func, rest_args, true, pos, - level, ) } else { // Normal call of script function @@ -675,7 +677,7 @@ impl Engine { } let result = self.call_script_fn( - scope, global, caches, lib, &mut None, func, args, true, pos, level, + global, caches, lib, level, scope, &mut None, func, args, true, pos, ); // Restore the original reference @@ -695,7 +697,7 @@ impl Engine { let hash = hashes.native(); self.exec_native_fn_call( - global, caches, lib, fn_name, op_token, hash, args, is_ref_mut, pos, level, + global, caches, lib, level, fn_name, op_token, hash, args, is_ref_mut, pos, ) } @@ -703,20 +705,20 @@ impl Engine { #[inline] pub(crate) fn get_arg_value( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, arg_expr: &Expr, - level: usize, ) -> RhaiResultOf<(Dynamic, Position)> { // Literal values if let Some(value) = arg_expr.get_literal_value() { self.track_operation(global, arg_expr.start_position())?; #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, arg_expr, level)?; + self.run_debugger(global, caches, lib, level, scope, this_ptr, arg_expr)?; return Ok((value, arg_expr.start_position())); } @@ -727,7 +729,7 @@ impl Engine { matches!(status, crate::eval::DebuggerStatus::FunctionExit(..)) }); - let result = self.eval_expr(scope, global, caches, lib, this_ptr, arg_expr, level); + let result = self.eval_expr(global, caches, lib, level, scope, this_ptr, arg_expr); // Restore function exit status #[cfg(feature = "debugging")] @@ -743,13 +745,13 @@ impl Engine { global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, fn_name: &str, mut hash: FnCallHashes, target: &mut crate::eval::Target, mut call_args: &mut [Dynamic], first_arg_pos: Position, fn_call_pos: Position, - level: usize, ) -> RhaiResultOf<(Dynamic, bool)> { let is_ref_mut = target.is_ref(); @@ -781,10 +783,11 @@ impl Engine { // Map it to name(args) in function-call style self.exec_fn_call( - None, global, caches, lib, + level, + None, fn_name, None, new_hash, @@ -792,7 +795,6 @@ impl Engine { false, false, fn_call_pos, - level, ) } KEYWORD_FN_PTR_CALL => { @@ -837,10 +839,11 @@ impl Engine { // Map it to name(args) in function-call style self.exec_fn_call( - None, global, caches, lib, + level, + None, &fn_name, None, new_hash, @@ -848,7 +851,6 @@ impl Engine { is_ref_mut, true, fn_call_pos, - level, ) } KEYWORD_FN_PTR_CURRY => { @@ -938,10 +940,11 @@ impl Engine { args.extend(call_args.iter_mut()); self.exec_fn_call( - None, global, caches, lib, + level, + None, fn_name, None, hash, @@ -949,7 +952,6 @@ impl Engine { is_ref_mut, true, fn_call_pos, - level, ) } }?; @@ -965,10 +967,11 @@ impl Engine { /// Call a function in normal function-call style. pub(crate) fn make_function_call( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, fn_name: &str, op_token: Option<&Token>, @@ -977,7 +980,6 @@ impl Engine { hashes: FnCallHashes, capture_scope: bool, pos: Position, - level: usize, ) -> RhaiResult { let mut first_arg = first_arg; let mut a_expr = args_expr; @@ -994,7 +996,7 @@ impl Engine { KEYWORD_FN_PTR_CALL if total_args >= 1 => { let arg = first_arg.unwrap(); let (arg_value, arg_pos) = - self.get_arg_value(scope, global, caches, lib, this_ptr, arg, level)?; + self.get_arg_value(global, caches, lib, level, scope, this_ptr, arg)?; if !arg_value.is::() { let typ = self.map_type_name(arg_value.type_name()); @@ -1035,7 +1037,7 @@ impl Engine { KEYWORD_FN_PTR if total_args == 1 => { let arg = first_arg.unwrap(); let (arg_value, arg_pos) = - self.get_arg_value(scope, global, caches, lib, this_ptr, arg, level)?; + self.get_arg_value(global, caches, lib, level, scope, this_ptr, arg)?; // Fn - only in function call style return arg_value @@ -1050,7 +1052,7 @@ impl Engine { KEYWORD_FN_PTR_CURRY if total_args > 1 => { let first = first_arg.unwrap(); let (arg_value, arg_pos) = - self.get_arg_value(scope, global, caches, lib, this_ptr, first, level)?; + self.get_arg_value(global, caches, lib, level, scope, this_ptr, first)?; if !arg_value.is::() { let typ = self.map_type_name(arg_value.type_name()); @@ -1062,7 +1064,7 @@ impl Engine { // Append the new curried arguments to the existing list. let fn_curry = a_expr.iter().try_fold(fn_curry, |mut curried, expr| { let (value, ..) = - self.get_arg_value(scope, global, caches, lib, this_ptr, expr, level)?; + self.get_arg_value(global, caches, lib, level, scope, this_ptr, expr)?; curried.push(value); Ok::<_, RhaiError>(curried) })?; @@ -1075,7 +1077,7 @@ impl Engine { crate::engine::KEYWORD_IS_SHARED if total_args == 1 => { let arg = first_arg.unwrap(); let (arg_value, ..) = - self.get_arg_value(scope, global, caches, lib, this_ptr, arg, level)?; + self.get_arg_value(global, caches, lib, level, scope, this_ptr, arg)?; return Ok(arg_value.is_shared().into()); } @@ -1084,14 +1086,14 @@ impl Engine { crate::engine::KEYWORD_IS_DEF_FN if total_args == 2 => { let first = first_arg.unwrap(); let (arg_value, arg_pos) = - self.get_arg_value(scope, global, caches, lib, this_ptr, first, level)?; + self.get_arg_value(global, caches, lib, level, scope, this_ptr, first)?; let fn_name = arg_value .into_immutable_string() .map_err(|typ| self.make_type_mismatch_err::(typ, arg_pos))?; let (arg_value, arg_pos) = - self.get_arg_value(scope, global, caches, lib, this_ptr, &a_expr[0], level)?; + self.get_arg_value(global, caches, lib, level, scope, this_ptr, &a_expr[0])?; let num_params = arg_value .as_int() @@ -1110,7 +1112,7 @@ impl Engine { KEYWORD_IS_DEF_VAR if total_args == 1 => { let arg = first_arg.unwrap(); let (arg_value, arg_pos) = - self.get_arg_value(scope, global, caches, lib, this_ptr, arg, level)?; + self.get_arg_value(global, caches, lib, level, scope, this_ptr, arg)?; let var_name = arg_value .into_immutable_string() .map_err(|typ| self.make_type_mismatch_err::(typ, arg_pos))?; @@ -1125,12 +1127,12 @@ impl Engine { let orig_imports_len = global.num_imports(); let arg = first_arg.unwrap(); let (arg_value, pos) = - self.get_arg_value(scope, global, caches, lib, this_ptr, arg, level)?; + self.get_arg_value(global, caches, lib, level, scope, this_ptr, arg)?; let s = &arg_value .into_immutable_string() .map_err(|typ| self.make_type_mismatch_err::(typ, pos))?; let result = - self.eval_script_expr_in_place(scope, global, caches, lib, s, pos, level + 1); + self.eval_script_expr_in_place(global, caches, lib, level + 1, scope, s, pos); // IMPORTANT! If the eval defines new variables in the current scope, // all variable offsets from this point on will be mis-aligned. @@ -1172,7 +1174,7 @@ impl Engine { .copied() .chain(a_expr.iter()) .try_for_each(|expr| { - self.get_arg_value(scope, global, caches, lib, this_ptr, expr, level) + self.get_arg_value(global, caches, lib, level, scope, this_ptr, expr) .map(|(value, ..)| arg_values.push(value.flatten())) })?; args.extend(curry.iter_mut()); @@ -1183,8 +1185,8 @@ impl Engine { return self .exec_fn_call( - scope, global, caches, lib, name, op_token, hashes, &mut args, is_ref_mut, - false, pos, level, + global, caches, lib, level, scope, name, op_token, hashes, &mut args, + is_ref_mut, false, pos, ) .map(|(v, ..)| v); } @@ -1200,16 +1202,16 @@ impl Engine { let first_expr = first_arg.unwrap(); #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, first_expr, level)?; + self.run_debugger(global, caches, lib, level, scope, this_ptr, first_expr)?; // func(x, ...) -> x.func(...) a_expr.iter().try_for_each(|expr| { - self.get_arg_value(scope, global, caches, lib, this_ptr, expr, level) + self.get_arg_value(global, caches, lib, level, scope, this_ptr, expr) .map(|(value, ..)| arg_values.push(value.flatten())) })?; let (mut target, _pos) = - self.search_namespace(scope, global, lib, this_ptr, first_expr, level)?; + self.search_namespace(global, caches, lib, level, scope, this_ptr, first_expr)?; if target.is_read_only() { target = target.into_owned(); @@ -1236,7 +1238,7 @@ impl Engine { .into_iter() .chain(a_expr.iter()) .try_for_each(|expr| { - self.get_arg_value(scope, global, caches, lib, this_ptr, expr, level) + self.get_arg_value(global, caches, lib, level, scope, this_ptr, expr) .map(|(value, ..)| arg_values.push(value.flatten())) })?; args.extend(curry.iter_mut()); @@ -1246,8 +1248,8 @@ impl Engine { } self.exec_fn_call( - None, global, caches, lib, name, op_token, hashes, &mut args, is_ref_mut, false, pos, - level, + global, caches, lib, level, None, name, op_token, hashes, &mut args, is_ref_mut, false, + pos, ) .map(|(v, ..)| v) } @@ -1256,17 +1258,17 @@ impl Engine { #[cfg(not(feature = "no_module"))] pub(crate) fn make_qualified_function_call( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, namespace: &crate::ast::Namespace, fn_name: &str, args_expr: &[Expr], hash: u64, pos: Position, - level: usize, ) -> RhaiResult { let mut arg_values = FnArgsVec::with_capacity(args_expr.len()); let mut args = FnArgsVec::with_capacity(args_expr.len()); @@ -1280,20 +1282,20 @@ impl Engine { // and avoid cloning the value if !args_expr.is_empty() && args_expr[0].is_variable_access(true) { #[cfg(feature = "debugging")] - self.run_debugger(scope, global, lib, this_ptr, &args_expr[0], level)?; + self.run_debugger(global, caches, lib, level, scope, this_ptr, &args_expr[0])?; // func(x, ...) -> x.func(...) arg_values.push(Dynamic::UNIT); args_expr.iter().skip(1).try_for_each(|expr| { - self.get_arg_value(scope, global, caches, lib, this_ptr, expr, level) + self.get_arg_value(global, caches, lib, level, scope, this_ptr, expr) .map(|(value, ..)| arg_values.push(value.flatten())) })?; // Get target reference to first argument let first_arg = &args_expr[0]; let (target, _pos) = - self.search_scope_only(scope, global, lib, this_ptr, first_arg, level)?; + self.search_scope_only(global, caches, lib, level, scope, this_ptr, first_arg)?; self.track_operation(global, _pos)?; @@ -1316,7 +1318,7 @@ impl Engine { } else { // func(..., ...) or func(mod::x, ...) args_expr.iter().try_for_each(|expr| { - self.get_arg_value(scope, global, caches, lib, this_ptr, expr, level) + self.get_arg_value(global, caches, lib, level, scope, this_ptr, expr) .map(|(value, ..)| arg_values.push(value.flatten())) })?; args.extend(arg_values.iter_mut()); @@ -1393,7 +1395,7 @@ impl Engine { let orig_source = mem::replace(&mut global.source, module.id_raw().cloned()); let result = self.call_script_fn( - new_scope, global, caches, lib, &mut None, fn_def, &mut args, true, pos, level, + global, caches, lib, level, new_scope, &mut None, fn_def, &mut args, true, pos, ); global.source = orig_source; @@ -1440,13 +1442,13 @@ impl Engine { /// 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, caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, script: &str, _pos: Position, - level: usize, ) -> RhaiResult { self.track_operation(global, _pos)?; @@ -1479,20 +1481,20 @@ impl Engine { } // Evaluate the AST - self.eval_global_statements(scope, global, caches, statements, lib, level) + self.eval_global_statements(global, caches, lib, level, scope, statements) } /// Evaluate a function call expression. pub(crate) fn eval_fn_call_expr( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, expr: &FnCallExpr, pos: Position, - level: usize, ) -> RhaiResult { let FnCallExpr { #[cfg(not(feature = "no_module"))] @@ -1510,12 +1512,12 @@ impl Engine { // Short-circuit native binary operator call if under Fast Operators mode if op_token.is_some() && self.fast_operators() && args.len() == 2 { let mut lhs = self - .get_arg_value(scope, global, caches, lib, this_ptr, &args[0], level)? + .get_arg_value(global, caches, lib, level, scope, this_ptr, &args[0])? .0 .flatten(); let mut rhs = self - .get_arg_value(scope, global, caches, lib, this_ptr, &args[1], level)? + .get_arg_value(global, caches, lib, level, scope, this_ptr, &args[1])? .0 .flatten(); @@ -1531,8 +1533,8 @@ impl Engine { return self .exec_fn_call( - None, global, caches, lib, name, op_token, *hashes, operands, false, false, - pos, level, + global, caches, lib, level, None, name, op_token, *hashes, operands, false, + false, pos, ) .map(|(v, ..)| v); } @@ -1543,7 +1545,7 @@ impl Engine { let hash = hashes.native(); return self.make_qualified_function_call( - scope, global, caches, lib, this_ptr, namespace, name, args, hash, pos, level, + global, caches, lib, level, scope, this_ptr, namespace, name, args, hash, pos, ); } @@ -1554,8 +1556,8 @@ impl Engine { ); self.make_function_call( - scope, global, caches, lib, this_ptr, name, op_token, first_arg, args, *hashes, - *capture, pos, level, + global, caches, lib, level, scope, this_ptr, name, op_token, first_arg, args, *hashes, + *capture, pos, ) } } diff --git a/src/func/native.rs b/src/func/native.rs index 9d44125c..912f9d79 100644 --- a/src/func/native.rs +++ b/src/func/native.rs @@ -393,13 +393,13 @@ impl<'a> NativeCallContext<'a> { global, caches, self.lib, + self.level + 1, fn_name, op_token, calc_fn_hash(None, fn_name, args_len), args, is_ref_mut, Position::NONE, - self.level + 1, ) .map(|(r, ..)| r); } @@ -418,10 +418,11 @@ impl<'a> NativeCallContext<'a> { self.engine() .exec_fn_call( - None, global, caches, self.lib, + self.level + 1, + None, fn_name, op_token, hash, @@ -429,7 +430,6 @@ impl<'a> NativeCallContext<'a> { is_ref_mut, is_method_call, Position::NONE, - self.level + 1, ) .map(|(r, ..)| r) } diff --git a/src/func/script.rs b/src/func/script.rs index 476343af..b80d74ae 100644 --- a/src/func/script.rs +++ b/src/func/script.rs @@ -24,16 +24,16 @@ impl Engine { /// **DO NOT** reuse the argument values unless for the first `&mut` argument - all others are silently replaced by `()`! pub(crate) fn call_script_fn( &self, - scope: &mut Scope, global: &mut GlobalRuntimeState, caches: &mut Caches, lib: &[&Module], + level: usize, + scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, fn_def: &ScriptFnDef, args: &mut FnCallArgs, rewind_scope: bool, pos: Position, - level: usize, ) -> RhaiResult { #[cold] #[inline(never)] @@ -140,20 +140,20 @@ impl Engine { #[cfg(feature = "debugging")] { let node = crate::ast::Stmt::Noop(fn_def.body.position()); - self.run_debugger(scope, global, lib, this_ptr, &node, level)?; + self.run_debugger(global, caches, lib, level, scope, this_ptr, &node)?; } // Evaluate the function let mut _result = self .eval_stmt_block( - scope, global, caches, lib, + level, + scope, this_ptr, &fn_def.body, rewind_scope, - level, ) .or_else(|err| match *err { // Convert return statement to return value @@ -190,7 +190,9 @@ impl Engine { Ok(ref r) => crate::eval::DebuggerEvent::FunctionExitWithValue(r), Err(ref err) => crate::eval::DebuggerEvent::FunctionExitWithError(err), }; - match self.run_debugger_raw(scope, global, lib, this_ptr, node, event, level) { + match self + .run_debugger_raw(global, caches, lib, level, scope, this_ptr, node, event) + { Ok(_) => (), Err(err) => _result = Err(err), } diff --git a/src/module/mod.rs b/src/module/mod.rs index 59ead075..f0f1a982 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -3,6 +3,7 @@ #[cfg(feature = "metadata")] use crate::api::type_names::format_type; use crate::ast::FnAccess; +use crate::eval::Caches; use crate::func::{ shared_take_or_clone, CallableFunction, FnCallArgs, IteratorFn, RegisterNativeFunction, SendSync, @@ -1984,7 +1985,9 @@ impl Module { let orig_constants = std::mem::take(&mut global.constants); // Run the script - let result = engine.eval_ast_with_scope_raw(&mut scope, global, ast, 0); + let caches = &mut Caches::new(); + + let result = engine.eval_ast_with_scope_raw(global, caches, 0, &mut scope, ast); // Create new module let mut module = Module::new(); diff --git a/src/optimizer.rs b/src/optimizer.rs index 6cb4beb2..bd7b0140 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -152,13 +152,13 @@ impl<'a> OptimizerState<'a> { &mut self.global, &mut self.caches, lib, + 0, fn_name, op_token, calc_fn_hash(None, fn_name, arg_values.len()), &mut arg_values.iter_mut().collect::>(), false, Position::NONE, - 0, ) .ok() .map(|(v, ..)| v) diff --git a/src/parser.rs b/src/parser.rs index 31391363..f0c3843f 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2909,12 +2909,12 @@ impl Engine { let mut this_ptr = None; let context = EvalContext::new( self, - &mut state.stack, &mut state.global, None, &[], - &mut this_ptr, level, + &mut state.stack, + &mut this_ptr, ); match filter(false, info, context) {