Clean
This commit is contained in:
parent
1e758afaa2
commit
0110ea2d57
|
@ -75,12 +75,10 @@ impl<'a, E: Externals> Interpreter<'a, E> {
|
||||||
func.clone(),
|
func.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut function_stack = VecDeque::new();
|
let mut call_stack = VecDeque::new();
|
||||||
function_stack.push_back(context);
|
call_stack.push_back(context);
|
||||||
|
|
||||||
self.run_interpreter_loop(&mut function_stack)?;
|
self.run_interpreter_loop(&mut call_stack)?;
|
||||||
|
|
||||||
// println!("return stack: {:?}", self.value_stack);
|
|
||||||
|
|
||||||
Ok(func.signature().return_type().map(|_vt| {
|
Ok(func.signature().return_type().map(|_vt| {
|
||||||
let return_value = self.value_stack
|
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<FunctionContext>) -> Result<(), Trap> {
|
fn run_interpreter_loop(&mut self, call_stack: &mut VecDeque<FunctionContext>) -> Result<(), Trap> {
|
||||||
loop {
|
loop {
|
||||||
let mut function_context = function_stack
|
let mut function_context = call_stack
|
||||||
.pop_back()
|
.pop_back()
|
||||||
.expect("on loop entry - not empty; on loop continue - checking for emptiness; qed");
|
.expect("on loop entry - not empty; on loop continue - checking for emptiness; qed");
|
||||||
let function_ref = function_context.function.clone();
|
let function_ref = function_context.function.clone();
|
||||||
|
@ -115,21 +113,22 @@ impl<'a, E: Externals> Interpreter<'a, E> {
|
||||||
|
|
||||||
match function_return {
|
match function_return {
|
||||||
RunResult::Return => {
|
RunResult::Return => {
|
||||||
if function_stack.back().is_none() {
|
if call_stack.back().is_none() {
|
||||||
// There are no more frames in the call stack.
|
// This was the last frame in the call stack. This means we
|
||||||
|
// are done executing.
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
RunResult::NestedCall(nested_func) => {
|
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());
|
return Err(TrapKind::StackOverflow.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
match *nested_func.as_internal() {
|
match *nested_func.as_internal() {
|
||||||
FuncInstanceInternal::Internal { .. } => {
|
FuncInstanceInternal::Internal { .. } => {
|
||||||
let nested_context = function_context.nested(nested_func.clone()).map_err(Trap::new)?;
|
let nested_context = function_context.nested(nested_func.clone()).map_err(Trap::new)?;
|
||||||
function_stack.push_back(function_context);
|
call_stack.push_back(function_context);
|
||||||
function_stack.push_back(nested_context);
|
call_stack.push_back(nested_context);
|
||||||
},
|
},
|
||||||
FuncInstanceInternal::Host { ref signature, .. } => {
|
FuncInstanceInternal::Host { ref signature, .. } => {
|
||||||
let args = prepare_function_args(signature, &mut self.value_stack);
|
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 {
|
if let Some(return_val) = return_val {
|
||||||
self.value_stack.push(return_val).map_err(Trap::new)?;
|
self.value_stack.push(return_val).map_err(Trap::new)?;
|
||||||
}
|
}
|
||||||
function_stack.push_back(function_context);
|
call_stack.push_back(function_context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue