From 8e154377dd97c62881dede5ac733717a6252878c Mon Sep 17 00:00:00 2001 From: mertcandav Date: Fri, 2 Feb 2024 16:01:15 +0300 Subject: [PATCH] api: use fixed-with integers --- api/types.hpp | 37 +++++++++++++++--------------- api/utf16.hpp | 4 ++-- api/utf8.hpp | 62 +++++++++++++++++++++++++-------------------------- 3 files changed, 51 insertions(+), 52 deletions(-) diff --git a/api/types.hpp b/api/types.hpp index cf1ba062e..29cb37d9d 100644 --- a/api/types.hpp +++ b/api/types.hpp @@ -6,35 +6,35 @@ #define __JULE_TYPES_HPP #include +#include #include #include "platform.hpp" namespace jule { + using I8 = std::int8_t; + using I16 = std::int16_t; + using I32 = std::int32_t; + using I64 = std::int64_t; + using U8 = std::uint8_t; + using U16 = std::uint16_t; + using U32 = std::uint32_t; + using U64 = std::uint64_t; + typedef float F32; + typedef double F64; + typedef bool Bool; #ifdef ARCH_X32 - typedef unsigned long int Uint; - typedef signed long int Int; - typedef unsigned long int Uintptr; + using Uint = std::uint32_t; + using Int = std::int32_t; + using Uintptr = std::uint32_t; #else - typedef unsigned long long int Uint; - typedef signed long long int Int; - typedef unsigned long long int Uintptr; + using Uint = std::uint64_t; + using Int = std::int64_t; + using Uintptr = std::uint64_t; #endif - typedef signed char I8; - typedef signed short int I16; - typedef signed long int I32; - typedef signed long long int I64; - typedef unsigned char U8; - typedef unsigned short int U16; - typedef unsigned long int U32; - typedef unsigned long long int U64; - typedef float F32; - typedef double F64; - typedef bool Bool; - constexpr decltype(nullptr) nil = nullptr; constexpr jule::F32 MAX_F32 = 3.402823466e+38F; // 0x1p127 * (1 + (1 - 0x1p-23)) @@ -44,7 +44,6 @@ namespace jule constexpr jule::I64 MAX_I64 = 9223372036854775807LL; constexpr jule::I64 MIN_I64 = -9223372036854775807 - 1; constexpr jule::U64 MAX_U64 = 18446744073709551615LLU; - } // namespace jule inline std::ostream &operator<<(std::ostream &stream, const jule::I8 &x) diff --git a/api/utf16.hpp b/api/utf16.hpp index 45cc38d3f..9d5337eae 100644 --- a/api/utf16.hpp +++ b/api/utf16.hpp @@ -108,11 +108,11 @@ namespace jule std::tuple utf16_encode_rune(jule::I32 r) { if (r < jule::UTF16_SURR_SELF || r > jule::UTF16_MAX_RUNE) - return std::make_tuple( + return std::make_tuple( jule::UTF16_REPLACEMENT_CHAR, jule::UTF16_REPLACEMENT_CHAR); r -= jule::UTF16_SURR_SELF; - return std::make_tuple( + return std::make_tuple( jule::UTF16_SURR1 + (r >> 10) & 0x3ff, jule::UTF16_SURR2 + r & 0x3ff); } diff --git a/api/utf8.hpp b/api/utf8.hpp index 8ed6aee9e..1873c2581 100644 --- a/api/utf8.hpp +++ b/api/utf8.hpp @@ -21,32 +21,32 @@ namespace jule { - constexpr signed int UTF8_RUNE_ERROR = 65533; - constexpr signed int UTF8_MASKX = 63; - constexpr signed int UTF8_MASK2 = 31; - constexpr signed int UTF8_MASK3 = 15; - constexpr signed int UTF8_MASK4 = 7; - constexpr signed int UTF8_LOCB = 128; - constexpr signed int UTF8_HICB = 191; - constexpr signed int UTF8_XX = 241; - constexpr signed int UTF8_AS = 240; - constexpr signed int UTF8_S1 = 2; - constexpr signed int UTF8_S2 = 19; - constexpr signed int UTF8_S3 = 3; - constexpr signed int UTF8_S4 = 35; - constexpr signed int UTF8_S5 = 52; - constexpr signed int UTF8_S6 = 4; - constexpr signed int UTF8_S7 = 68; - constexpr signed int UTF8_RUNE1_MAX = 127; - constexpr signed int UTF8_RUNE2_MAX = 2047; - constexpr signed int UTF8_RUNE3_MAX = 65535; - constexpr signed int UTF8_TX = 128; - constexpr signed int UTF8_T2 = 192; - constexpr signed int UTF8_T3 = 224; - constexpr signed int UTF8_T4 = 240; - constexpr signed int UTF8_MAX_RUNE = 1114111; - constexpr signed int UTF8_SURROGATE_MIN = 55296; - constexpr signed int UTF8_SURROGATE_MAX = 57343; + constexpr jule::I32 UTF8_RUNE_ERROR = 65533; + constexpr jule::I32 UTF8_MASKX = 63; + constexpr jule::I32 UTF8_MASK2 = 31; + constexpr jule::I32 UTF8_MASK3 = 15; + constexpr jule::I32 UTF8_MASK4 = 7; + constexpr jule::I32 UTF8_LOCB = 128; + constexpr jule::I32 UTF8_HICB = 191; + constexpr jule::I32 UTF8_XX = 241; + constexpr jule::I32 UTF8_AS = 240; + constexpr jule::I32 UTF8_S1 = 2; + constexpr jule::I32 UTF8_S2 = 19; + constexpr jule::I32 UTF8_S3 = 3; + constexpr jule::I32 UTF8_S4 = 35; + constexpr jule::I32 UTF8_S5 = 52; + constexpr jule::I32 UTF8_S6 = 4; + constexpr jule::I32 UTF8_S7 = 68; + constexpr jule::I32 UTF8_RUNE1_MAX = 127; + constexpr jule::I32 UTF8_RUNE2_MAX = 2047; + constexpr jule::I32 UTF8_RUNE3_MAX = 65535; + constexpr jule::I32 UTF8_TX = 128; + constexpr jule::I32 UTF8_T2 = 192; + constexpr jule::I32 UTF8_T3 = 224; + constexpr jule::I32 UTF8_T4 = 240; + constexpr jule::I32 UTF8_MAX_RUNE = 1114111; + constexpr jule::I32 UTF8_SURROGATE_MIN = 55296; + constexpr jule::I32 UTF8_SURROGATE_MAX = 57343; // Declarations @@ -344,7 +344,7 @@ namespace jule utf8_decode_rune_str(const char *s, const std::size_t len) { if (len == 0) - return std::make_tuple(jule::UTF8_RUNE_ERROR, 0); + return std::make_tuple(jule::UTF8_RUNE_ERROR, 0); const auto s0 = static_cast(s[0]); const jule::U8 x = jule::utf8_first[s0]; @@ -359,11 +359,11 @@ namespace jule const auto sz = static_cast(x & 7); const struct jule::UTF8AcceptRange accept = jule::utf8_accept_ranges[x >> 4]; if (len < sz) - return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); + return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); const auto s1 = static_cast(s[1]); if (s1 < accept.lo || accept.hi < s1) - return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); + return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); if (sz <= 2) return std::make_tuple( @@ -373,7 +373,7 @@ namespace jule const auto s2 = static_cast(s[2]); if (s2 < jule::UTF8_LOCB || jule::UTF8_HICB < s2) - return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); + return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); if (sz <= 3) return std::make_tuple( @@ -384,7 +384,7 @@ namespace jule const auto s3 = static_cast(s[3]); if (s3 < jule::UTF8_LOCB || jule::UTF8_HICB < s3) - return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); + return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); return std::make_tuple((static_cast(s0 & jule::UTF8_MASK4) << 18) | (static_cast(s1 & jule::UTF8_MASKX) << 12) |