From c7405c44b86e349ad701da627aafee6778fa9eb3 Mon Sep 17 00:00:00 2001 From: skanehira Date: Mon, 13 Nov 2023 00:14:10 +0900 Subject: [PATCH] chore: refactor push_frame --- src/execution/op.rs | 4 ++-- src/execution/runtime.rs | 24 +----------------------- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/src/execution/op.rs b/src/execution/op.rs index 2981ef4..a14d289 100644 --- a/src/execution/op.rs +++ b/src/execution/op.rs @@ -144,8 +144,8 @@ pub fn get_else_or_end_address(insts: &[Instruction], pc: isize) -> Result, call_stack: &mut Vec, func: &InternalFuncInst) { let arity = func.func_type.results.len(); - let len = stack.len(); - let mut locals = stack.split_off(len - func.func_type.params.len()); + let bottom = stack.len() - func.func_type.params.len(); + let mut locals = stack.split_off(bottom); for local in func.code.locals.iter() { match local { diff --git a/src/execution/runtime.rs b/src/execution/runtime.rs index b5fc9c8..7b5144f 100644 --- a/src/execution/runtime.rs +++ b/src/execution/runtime.rs @@ -3,7 +3,6 @@ use super::op::*; use super::store::{Exports, Store}; use super::value::{ExternalVal, Frame, Label, StackAccess, Value}; use crate::binary::instruction::*; -use crate::binary::types::ValueType; use crate::execution::error::Error; use crate::execution::value::LabelKind; use crate::{load, store, Importer}; @@ -132,31 +131,10 @@ impl Runtime { } fn invoke_internal(&mut self, func: InternalFuncInst) -> Result> { - let bottom = self.stack.len() - func.func_type.params.len(); - let mut locals: Vec<_> = self.stack.split_off(bottom).into_iter().collect(); - - for local in func.code.locals.iter() { - match local { - ValueType::I32 => locals.push(Value::I32(0)), - ValueType::I64 => locals.push(Value::I64(0)), - ValueType::F32 => locals.push(Value::F32(0.0)), - ValueType::F64 => locals.push(Value::F64(0.0)), - } - } - let arity = func.func_type.results.len(); - let frame = Frame { - pc: -1, - sp: self.stack.len(), - insts: func.code.body, - arity, - locals, - labels: vec![], - }; - self.call_stack.push(frame); + push_frame(&mut self.stack, &mut self.call_stack, &func); - trace!("call stack: {:?}", &self.call_stack.last()); self.execute()?; let result = if arity > 0 {