| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef LYTHON_TYPES_HEADER | ||
| 2 | #define LYTHON_TYPES_HEADER | ||
| 3 | |||
| 4 | #include <functional> | ||
| 5 | #include <list> | ||
| 6 | #include <string> | ||
| 7 | #include <string_view> | ||
| 8 | #include <unordered_map> | ||
| 9 | #include <unordered_set> | ||
| 10 | #include <vector> | ||
| 11 | |||
| 12 | #include <sstream> | ||
| 13 | |||
| 14 | #include "dependencies/xx_hash.h" | ||
| 15 | #include "utilities/allocator.h" | ||
| 16 | |||
| 17 | #ifdef __linux__ | ||
| 18 | # define KIWI_INLINE __attribute__((always_inline)) | ||
| 19 | #else | ||
| 20 | # define KIWI_INLINE __forceinline | ||
| 21 | #endif | ||
| 22 | |||
| 23 | // --------------- | ||
| 24 | namespace lython { | ||
| 25 | |||
| 26 | using uint64 = std::uint64_t; | ||
| 27 | using int64 = std::int64_t; | ||
| 28 | |||
| 29 | using uint32 = std::uint32_t; | ||
| 30 | using int32 = std::int32_t; | ||
| 31 | |||
| 32 | using uint16 = std::uint16_t; | ||
| 33 | using int16 = std::int16_t; | ||
| 34 | |||
| 35 | using uint8 = std::uint8_t; | ||
| 36 | using int8 = std::int8_t; | ||
| 37 | |||
| 38 | // using float8 = ; | ||
| 39 | // using float16 = ; | ||
| 40 | // using float24 = ; | ||
| 41 | using float32 = float; | ||
| 42 | using float64 = double; | ||
| 43 | |||
| 44 | // using bfloat16 = ; | ||
| 45 | // using float40 = ; | ||
| 46 | // using float80 = ; | ||
| 47 | // using float128 = ; | ||
| 48 | // using float256 = ; | ||
| 49 | |||
| 50 | using uchar = unsigned char; | ||
| 51 | |||
| 52 | template <typename V> | ||
| 53 | using AllocatorCPU = Allocator<V, device::CPU>; | ||
| 54 | |||
| 55 | template <typename V> | ||
| 56 | using Array = std::vector<V, AllocatorCPU<V>>; | ||
| 57 | |||
| 58 | template <typename V> | ||
| 59 | using List = std::list<V, AllocatorCPU<V>>; | ||
| 60 | |||
| 61 | using String = std::basic_string<char, std::char_traits<char>, AllocatorCPU<char>>; | ||
| 62 | |||
| 63 | using StringStream = std::basic_stringstream<char, std::char_traits<char>, AllocatorCPU<char>>; | ||
| 64 | |||
| 65 | using StringView = std::string_view; | ||
| 66 | } // namespace lython | ||
| 67 | |||
| 68 | // ------------ | ||
| 69 | namespace std { | ||
| 70 | |||
| 71 | // FIXME: BUILD_WEBASSEMBLY use clang by default so this is the same check | ||
| 72 | #if !BUILD_WEBASSEMBLY | ||
| 73 | template <> | ||
| 74 | struct hash<lython::String> { | ||
| 75 | using Key = lython::String; | ||
| 76 | |||
| 77 | std::size_t operator()(Key const& k) const noexcept { | ||
| 78 | 1385 | return lython::xx_hash_3((void*)k.data(), k.length()); | |
| 79 | // #ifdef __linux__ | ||
| 80 | // return std::_Hash_impl::hash(k.data(), k.length() * sizeof(Char)); | ||
| 81 | // #else | ||
| 82 | // return std::_Hash_array_representation(k.c_str(), k.size()); | ||
| 83 | // #endif | ||
| 84 | } | ||
| 85 | }; | ||
| 86 | #endif | ||
| 87 | //*/ | ||
| 88 | |||
| 89 | } // namespace std | ||
| 90 | |||
| 91 | // --------------- | ||
| 92 | namespace lython { | ||
| 93 | |||
| 94 | template <class _Ty, class _Dx = std::default_delete<_Ty>> | ||
| 95 | using Unique = std::unique_ptr<_Ty, _Dx>; | ||
| 96 | |||
| 97 | template <class _Ty> | ||
| 98 | using Shared = std::shared_ptr<_Ty>; | ||
| 99 | |||
| 100 | template <typename... Args> | ||
| 101 | using Tuple = std::tuple<Args...>; | ||
| 102 | |||
| 103 | template <typename A, typename B> | ||
| 104 | using Pair = std::pair<A, B>; | ||
| 105 | |||
| 106 | template <typename K, typename V, typename H = std::hash<K>> | ||
| 107 | using Dict = std::unordered_map<K, V, H, std::equal_to<K>, AllocatorCPU<std::pair<K const, V>>>; | ||
| 108 | |||
| 109 | template <typename V> | ||
| 110 | using Set = std::unordered_set<V, std::hash<V>, std::equal_to<V>, AllocatorCPU<V>>; | ||
| 111 | |||
| 112 | class LythonException: public std::exception {}; | ||
| 113 | |||
| 114 | } // namespace lython | ||
| 115 | |||
| 116 | #endif | ||
| 117 |