refactor(furvm): move thing operators to thing.cpp
This commit is contained in:
@@ -82,6 +82,65 @@ thing& thing::operator=(thing&& other) noexcept {
|
||||
return *this;
|
||||
}
|
||||
|
||||
static constexpr std::uint16_t thing_type_pair(thing_t lhs, thing_t rhs) {
|
||||
return (static_cast<std::uint16_t>(lhs) << 8) | static_cast<std::uint16_t>(rhs);
|
||||
}
|
||||
|
||||
thing_p operator+(const thing_p& lhs, const thing_p& rhs) {
|
||||
switch (thing_type_pair(lhs->m_type, rhs->m_type)) {
|
||||
case thing_type_pair(thing_t::Int32, thing_t::Int32): {
|
||||
auto res = thing::create(lhs->m_context, thing_t::Int32);
|
||||
res->int32() = lhs->int32() + rhs->int32();
|
||||
return res;
|
||||
}
|
||||
default: throw std::runtime_error("unexpected operator");
|
||||
}
|
||||
}
|
||||
|
||||
thing_p operator-(const thing_p& lhs, const thing_p& rhs) {
|
||||
switch (thing_type_pair(lhs->m_type, rhs->m_type)) {
|
||||
case thing_type_pair(thing_t::Int32, thing_t::Int32): {
|
||||
auto res = thing::create(lhs->m_context, thing_t::Int32);
|
||||
res->int32() = lhs->int32() - rhs->int32();
|
||||
return res;
|
||||
}
|
||||
default: throw std::runtime_error("unexpected operator");
|
||||
}
|
||||
}
|
||||
|
||||
thing_p operator*(const thing_p& lhs, const thing_p& rhs) {
|
||||
switch (thing_type_pair(lhs->m_type, rhs->m_type)) {
|
||||
case thing_type_pair(thing_t::Int32, thing_t::Int32): {
|
||||
auto res = thing::create(lhs->m_context, thing_t::Int32);
|
||||
res->int32() = lhs->int32() * rhs->int32();
|
||||
return res;
|
||||
}
|
||||
default: throw std::runtime_error("unexpected operator");
|
||||
}
|
||||
}
|
||||
|
||||
thing_p operator/(const thing_p& lhs, const thing_p& rhs) {
|
||||
switch (thing_type_pair(lhs->m_type, rhs->m_type)) {
|
||||
case thing_type_pair(thing_t::Int32, thing_t::Int32): {
|
||||
auto res = thing::create(lhs->m_context, thing_t::Int32);
|
||||
res->int32() = lhs->int32() / rhs->int32();
|
||||
return res;
|
||||
}
|
||||
default: throw std::runtime_error("unexpected operator");
|
||||
}
|
||||
}
|
||||
|
||||
thing_p operator%(const thing_p& lhs, const thing_p& rhs) {
|
||||
switch (thing_type_pair(lhs->m_type, rhs->m_type)) {
|
||||
case thing_type_pair(thing_t::Int32, thing_t::Int32): {
|
||||
auto res = thing::create(lhs->m_context, thing_t::Int32);
|
||||
res->int32() = lhs->int32() % rhs->int32();
|
||||
return res;
|
||||
}
|
||||
default: throw std::runtime_error("unexpected operator");
|
||||
}
|
||||
}
|
||||
|
||||
thing_p thing::clone(const thing_p& thing) {
|
||||
thing_handle id = thing->m_context->m_things.size();
|
||||
if (!thing->m_context->m_deadThings.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user