Skip to content

Commit

Permalink
Update stack top in {unary,binary}_op() helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed May 22, 2020
1 parent 81b6d0e commit b9d3064
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/fizzy/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,26 +378,25 @@ inline bool store_into_memory(bytes& memory, OperandStack& stack, const uint8_t*
template <typename Op>
inline void unary_op(OperandStack& stack, Op op) noexcept
{
using T = decltype(op(stack.pop()));
const auto a = static_cast<T>(stack.pop());
stack.push(op(a));
using T = decltype(op(stack.top()));
stack.top() = op(static_cast<T>(stack.top()));
}

template <typename Op>
inline void binary_op(OperandStack& stack, Op op) noexcept
{
using T = decltype(op(stack.pop(), stack.pop()));
using T = decltype(op(stack.top(), stack.top()));
const auto val2 = static_cast<T>(stack.pop());
const auto val1 = static_cast<T>(stack.pop());
stack.push(static_cast<std::make_unsigned_t<T>>(op(val1, val2)));
const auto val1 = static_cast<T>(stack.top());
stack.top() = static_cast<std::make_unsigned_t<T>>(op(val1, val2));
}

template <typename T, template <typename> class Op>
inline void comparison_op(OperandStack& stack, Op<T> op) noexcept
{
const auto val2 = static_cast<T>(stack.pop());
const auto val1 = static_cast<T>(stack.pop());
stack.push(uint32_t{op(val1, val2)});
const auto val1 = static_cast<T>(stack.top());
stack.top() = uint32_t{op(val1, val2)};
}

template <typename T>
Expand Down

0 comments on commit b9d3064

Please sign in to comment.