Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auto GetStringPtrs(Runtime::Object* lhs, Runtime::Object* rhs) {
- using namespace Runtime;
- return pair(dynamic_cast<String*>(lhs), dynamic_cast<String*>(rhs));
- }
- auto GetNumberPtrs(Runtime::Object* lhs, Runtime::Object* rhs) {
- using namespace Runtime;
- return pair(dynamic_cast<Number*>(lhs), dynamic_cast<Number*>(rhs));
- }
- auto GetBoolPtrs(Runtime::Object* lhs, Runtime::Object* rhs) {
- using namespace Runtime;
- return pair(dynamic_cast<Bool*>(lhs), dynamic_cast<Bool*>(rhs));
- }
- template <typename BinOp>
- ObjectHolder ArithOpOrError(Runtime::Object* lhs, Runtime::Object* rhs,
- BinOp op) {
- using namespace Runtime;
- auto [str1, str2] = GetStringPtrs(lhs, rhs);
- if (str1 && str2)
- return ObjectHolder::Own(String(op(str1->GetValue(), str2->GetValue())));
- auto [num1, num2] = GetNumberPtrs(lhs, rhs);
- if (num1 && num2)
- return ObjectHolder::Own(Number(op(num1->GetValue(), num2->GetValue())));
- auto [bool1, bool2] = GetBoolPtrs(lhs, rhs);
- if (bool1 && bool2)
- return ObjectHolder::Own(Bool(op(bool1->GetValue(), bool2->GetValue())));
- throw runtime_error("not the same type or not ValueObject");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement