Skip to content

Commit 59390c9

Browse files
committed
refactor
1 parent 78d6da0 commit 59390c9

File tree

3 files changed

+41
-37
lines changed

3 files changed

+41
-37
lines changed

argon/vm/areval.cpp

+2-35
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,6 @@
2424
using namespace argon::vm;
2525
using namespace argon::vm::datatype;
2626

27-
ArObject *Binary(ArObject *l, ArObject *r, int offset) {
28-
BinaryOp lop = nullptr;
29-
BinaryOp rop = nullptr;
30-
ArObject *result = nullptr;
31-
32-
if (AR_GET_TYPE(l)->ops != nullptr)
33-
lop = AR_GET_BINARY_OP(AR_GET_TYPE(l)->ops, offset);
34-
35-
if (AR_GET_TYPE(r)->ops != nullptr)
36-
rop = AR_GET_BINARY_OP(AR_GET_TYPE(r)->ops, offset);
37-
38-
if (lop != nullptr)
39-
result = lop(l, r);
40-
41-
if (rop != nullptr && result == nullptr && !IsPanickingFrame())
42-
result = rop(l, r);
43-
44-
return result;
45-
}
46-
47-
ArObject *BinaryOriented(ArObject *l, ArObject *r, int offset) {
48-
ArObject *result = nullptr;
49-
BinaryOp lop = nullptr;
50-
51-
if (AR_GET_TYPE(l)->ops != nullptr)
52-
lop = AR_GET_BINARY_OP(AR_GET_TYPE(l)->ops, offset);
53-
54-
if (lop != nullptr)
55-
result = lop(l, r);
56-
57-
return result;
58-
}
59-
6027
ArObject *GetCallableFromType(ArObject **type) {
6128
String *key;
6229
ArObject *ret;
@@ -597,14 +564,14 @@ ArObject *argon::vm::Eval(Fiber *fiber) {
597564
} while(0)
598565

599566
#define BINARY_OP4(first, second, op, opchar) \
600-
if ((ret = BinaryOriented(first, second, offsetof(OpSlots, op))) == nullptr) { \
567+
if ((ret = ExecBinaryOpOriented(first, second, offsetof(OpSlots, op))) == nullptr) { \
601568
if (!IsPanickingFrame()) { \
602569
ErrorFormat(kRuntimeError[0], kRuntimeError[2], #opchar, AR_TYPE_NAME(first), AR_TYPE_NAME(second)); \
603570
} \
604571
break; } \
605572

606573
#define BINARY_OP(op, opchar) \
607-
if ((ret = Binary(PEEK1(), TOP(), offsetof(OpSlots, op))) == nullptr) { \
574+
if ((ret = ExecBinaryOp(PEEK1(), TOP(), offsetof(OpSlots, op))) == nullptr) { \
608575
if (!IsPanickingFrame()) { \
609576
ErrorFormat(kRuntimeError[0], kRuntimeError[2], #opchar, AR_TYPE_NAME(PEEK1()), AR_TYPE_NAME(TOP())); \
610577
} \

argon/vm/datatype/arobject.cpp

+35-2
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,39 @@ ArObject *argon::vm::datatype::Compare(const ArObject *self, const ArObject *oth
396396
return result;
397397
}
398398

399+
ArObject *argon::vm::datatype::ExecBinaryOp(ArObject *left, ArObject *right, int offset) {
400+
BinaryOp lop = nullptr;
401+
BinaryOp rop = nullptr;
402+
ArObject *result = nullptr;
403+
404+
if (AR_GET_TYPE(left)->ops != nullptr)
405+
lop = AR_GET_BINARY_OP(AR_GET_TYPE(left)->ops, offset);
406+
407+
if (AR_GET_TYPE(right)->ops != nullptr)
408+
rop = AR_GET_BINARY_OP(AR_GET_TYPE(right)->ops, offset);
409+
410+
if (lop != nullptr)
411+
result = lop(left, right);
412+
413+
if (rop != nullptr && result == nullptr && !IsPanickingFrame())
414+
result = rop(left, right);
415+
416+
return result;
417+
}
418+
419+
ArObject *argon::vm::datatype::ExecBinaryOpOriented(ArObject *left, ArObject *right, int offset) {
420+
ArObject *result = nullptr;
421+
BinaryOp lop = nullptr;
422+
423+
if (AR_GET_TYPE(left)->ops != nullptr)
424+
lop = AR_GET_BINARY_OP(AR_GET_TYPE(left)->ops, offset);
425+
426+
if (lop != nullptr)
427+
result = lop(left, right);
428+
429+
return result;
430+
}
431+
399432
ArObject *HashWrapper(ArObject *func, ArObject *self, ArObject **args, ArObject *kwargs, ArSize argc) {
400433
return (ArObject *) UIntNew(AR_GET_TYPE(self)->hash(self));
401434
}
@@ -739,15 +772,15 @@ Tuple *CalculateMRO(const List *bases) {
739772
auto tail_list = ((List *) bases->objects[i]);
740773

741774
if (bases_idx != i && head == tail_list->objects[0])
742-
ListRemove(tail_list, (ArSSize)0);
775+
ListRemove(tail_list, (ArSSize) 0);
743776
}
744777

745778
if (!ListAppend(output, head)) {
746779
Release(output);
747780
return nullptr;
748781
}
749782

750-
ListRemove(head_list, (ArSSize)0);
783+
ListRemove(head_list, (ArSSize) 0);
751784
bases_idx = 0;
752785
}
753786

argon/vm/datatype/arobject.h

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ namespace argon::vm::datatype {
2424

2525
ArObject *Compare(const ArObject *self, const ArObject *other, CompareMode mode);
2626

27+
ArObject *ExecBinaryOp(ArObject *left, ArObject *right, int offset);
28+
29+
ArObject *ExecBinaryOpOriented(ArObject *left, ArObject *right, int offset);
30+
2731
ArObject *IteratorGet(ArObject *object, bool reversed);
2832

2933
ArObject *IteratorNext(ArObject *iterator);

0 commit comments

Comments
 (0)