| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef LYTHON_MAGIC_HEADER | ||
| 2 | #define LYTHON_MAGIC_HEADER | ||
| 3 | |||
| 4 | #include "../dtypes.h" | ||
| 5 | #include <iostream> | ||
| 6 | |||
| 7 | namespace lython { | ||
| 8 | |||
| 9 | template <typename T> | ||
| 10 | void print(T const& obj, std::ostream& out = std::cout) { | ||
| 11 | 1693 | obj.print(out); | |
| 12 | 1693 | } | |
| 13 | |||
| 14 | template <> | ||
| 15 | inline void print(String const& obj, std::ostream& out) { | ||
| 16 | 3 | out << obj; | |
| 17 | 3 | } | |
| 18 | |||
| 19 | template <> | ||
| 20 | inline void print(int const& obj, std::ostream& out) { | ||
| 21 | 256 | out << obj; | |
| 22 | 256 | } | |
| 23 | |||
| 24 | template <typename T> | ||
| 25 | void print(T* const& obj, std::ostream& out = std::cout) { | ||
| 26 | obj->print(out); | ||
| 27 | } | ||
| 28 | |||
| 29 | template <typename T> | ||
| 30 | String str(T const& obj) { | ||
| 31 |
1/2✓ Branch 1 taken 2047 times.
✗ Branch 2 not taken.
|
4094 | StringStream ss; |
| 32 |
1/2✓ Branch 1 taken 2047 times.
✗ Branch 2 not taken.
|
4094 | print(obj, ss); |
| 33 |
1/2✓ Branch 1 taken 2047 times.
✗ Branch 2 not taken.
|
8188 | return ss.str(); |
| 34 | 4094 | } | |
| 35 | |||
| 36 | template <typename T> | ||
| 37 | 1009 | String str(T* const& obj) { | |
| 38 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
1020 | if (obj == nullptr) { |
| 39 |
0/2✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
115 | return "None"; |
| 40 | } | ||
| 41 | 905 | return obj->__str__(); | |
| 42 | } | ||
| 43 | |||
| 44 | inline String str(String const& obj) { return obj; } | ||
| 45 | |||
| 46 | #define BINARY(X) \ | ||
| 47 | X(+, __add__(self, other)) \ | ||
| 48 | X(-, __sub__(self, other)) \ | ||
| 49 | X(*, __mul__(self, other)) \ | ||
| 50 | X(/, __truediv__(self, other)) \ | ||
| 51 | X(\/\/, __floordiv__(self, other)) \ | ||
| 52 | X(%, __mod__(self, other)) \ | ||
| 53 | X(**, __pow__(self, other)) \ | ||
| 54 | X(>>, __rshift__(self, other)) \ | ||
| 55 | X(<<, __lshift__(self, other)) \ | ||
| 56 | X(&, __and__(self, other)) \ | ||
| 57 | X(|, __or__(self, other)) \ | ||
| 58 | X(^, __xor__(self, other)) | ||
| 59 | |||
| 60 | #define COMP(X) \ | ||
| 61 | X(<, __lt__(self, other)) \ | ||
| 62 | X(>, __gt__(self, other)) \ | ||
| 63 | X(<=, __le__(self, other)) \ | ||
| 64 | X(>=, __ge__(self, other)) \ | ||
| 65 | X(==, __eq__(self, other)) \ | ||
| 66 | X(!=, __ne__(self, other)) | ||
| 67 | |||
| 68 | #define AUG(X) \ | ||
| 69 | X(-=, __isub__(self, other)) \ | ||
| 70 | X(+=, __iadd__(self, other)) \ | ||
| 71 | X(*=, __imul__(self, other)) \ | ||
| 72 | X(/=, __idiv__(self, other)) \ | ||
| 73 | X(\/\/=, __ifloordiv__(self, other)) \ | ||
| 74 | X(%=, __imod__(self, other)) \ | ||
| 75 | X(* *=, __ipow__(self, other)) \ | ||
| 76 | X(>>=, __irshit__(self, other)) \ | ||
| 77 | X(<<=, __ilshit__(self, other)) \ | ||
| 78 | X(&=, __iand__(self, other)) \ | ||
| 79 | X(|=, __ior__(self, other)) \ | ||
| 80 | X(^=, __ixor__(self, other)) | ||
| 81 | |||
| 82 | #define UNARY(X) \ | ||
| 83 | X(-, __neg__(self, other)) \ | ||
| 84 | X(+, __pos__(self, other)) \ | ||
| 85 | X(~, __invert__(self, other)) | ||
| 86 | |||
| 87 | } // namespace lython | ||
| 88 | |||
| 89 | #endif | ||
| 90 |