Skip to content

Commit

Permalink
Simplify {unary,binary}_op() implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Jul 16, 2020
1 parent 5112d5d commit dc41d64
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/fizzy/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,17 @@ inline bool store_into_memory(
template <typename Op>
inline void unary_op(OperandStack& stack, Op op) noexcept
{
using T = decltype(op(stack.top()));
stack.top() = op(static_cast<T>(stack.top()));
using T = decltype(op({}));
stack.top() = op(stack.top().as<T>());
}

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

template <typename T, template <typename> class Op>
Expand Down

0 comments on commit dc41d64

Please sign in to comment.