Skip to content

Commit

Permalink
chore: simplify push_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
skanehira committed Nov 12, 2023
1 parent 6d035e0 commit 0a5a415
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/execution/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use super::{
value::{Frame, Label, LabelKind, StackAccess, Value},
};
use crate::{
binary::instruction::Instruction, execution::error::Error, impl_binary_operation,
impl_cvtop_operation, impl_unary_operation,
binary::{instruction::Instruction, types::ValueType},
execution::error::Error,
impl_binary_operation, impl_cvtop_operation, impl_unary_operation,
};
use anyhow::{bail, Context as _, Result};
use log::trace;
Expand Down Expand Up @@ -146,12 +147,15 @@ pub fn push_frame(stack: &mut Vec<Value>, call_stack: &mut Vec<Frame>, func: &In
let len = stack.len();
let mut locals = stack.split_off(len - func.func_type.params.len());

let local_len = func.code.locals.len();
if local_len > locals.len() {
for _ in 0..local_len - locals.len() {
locals.push(Value::I32(0));
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 sp = stack.len();
let frame = Frame {
pc: -1,
Expand Down

0 comments on commit 0a5a415

Please sign in to comment.