Skip to content

Commit

Permalink
VM: handle all types in VM::newStackFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
mrunix00 committed Jul 25, 2024
1 parent 1d80e3e commit c96a5f6
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,21 @@ inline void VM::newStackFrame(const Segment &segment, size_t id) {
}
callStack.push_back(frame);
for (size_t i = frame.localsSize - 1; i != -1; i--) {
if (((uint64_t *) stack)[stackSize - 1] == VariableType::Type::I64) {
auto val = popDoubleStack();
setDoubleLocal(--i, val);
} else {
auto val = popStack();
setLocal(i, val);
switch (topStack().type) {
case VariableType::Type::I64:
case VariableType::Type::Object: {
auto val = popDoubleStack();
setDoubleLocal(--i, val);
} break;
case VariableType::Type::I32:
case VariableType::Type::U32:
case VariableType::Type::Bool: {
auto val = popStack();
setLocal(i, val);
} break;
case VariableType::Type::Function:
case VariableType::Type::Invalid:
throw std::runtime_error("Invalid stack operation!");
}
}
}
Expand Down

0 comments on commit c96a5f6

Please sign in to comment.