From 0110ea2d57d2b9b93f6d5b38c3642909ede807bf Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Thu, 14 Jun 2018 17:02:56 +0300 Subject: [PATCH] Clean --- src/runner.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/runner.rs b/src/runner.rs index 171410f..0c1b103 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -75,12 +75,10 @@ impl<'a, E: Externals> Interpreter<'a, E> { func.clone(), ); - let mut function_stack = VecDeque::new(); - function_stack.push_back(context); + let mut call_stack = VecDeque::new(); + call_stack.push_back(context); - self.run_interpreter_loop(&mut function_stack)?; - - // println!("return stack: {:?}", self.value_stack); + self.run_interpreter_loop(&mut call_stack)?; Ok(func.signature().return_type().map(|_vt| { let return_value = self.value_stack @@ -90,9 +88,9 @@ impl<'a, E: Externals> Interpreter<'a, E> { })) } - fn run_interpreter_loop(&mut self, function_stack: &mut VecDeque) -> Result<(), Trap> { + fn run_interpreter_loop(&mut self, call_stack: &mut VecDeque) -> Result<(), Trap> { loop { - let mut function_context = function_stack + let mut function_context = call_stack .pop_back() .expect("on loop entry - not empty; on loop continue - checking for emptiness; qed"); let function_ref = function_context.function.clone(); @@ -115,21 +113,22 @@ impl<'a, E: Externals> Interpreter<'a, E> { match function_return { RunResult::Return => { - if function_stack.back().is_none() { - // There are no more frames in the call stack. + if call_stack.back().is_none() { + // This was the last frame in the call stack. This means we + // are done executing. return Ok(()); } }, RunResult::NestedCall(nested_func) => { - if function_stack.len() + 1 >= DEFAULT_CALL_STACK_LIMIT { + if call_stack.len() + 1 >= DEFAULT_CALL_STACK_LIMIT { return Err(TrapKind::StackOverflow.into()); } match *nested_func.as_internal() { FuncInstanceInternal::Internal { .. } => { let nested_context = function_context.nested(nested_func.clone()).map_err(Trap::new)?; - function_stack.push_back(function_context); - function_stack.push_back(nested_context); + call_stack.push_back(function_context); + call_stack.push_back(nested_context); }, FuncInstanceInternal::Host { ref signature, .. } => { let args = prepare_function_args(signature, &mut self.value_stack); @@ -145,7 +144,7 @@ impl<'a, E: Externals> Interpreter<'a, E> { if let Some(return_val) = return_val { self.value_stack.push(return_val).map_err(Trap::new)?; } - function_stack.push_back(function_context); + call_stack.push_back(function_context); } } },