Skip to content

Commit

Permalink
api: use fixed-with integers
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Feb 2, 2024
1 parent a09de07 commit 8e15437
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 52 deletions.
37 changes: 18 additions & 19 deletions api/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@
#define __JULE_TYPES_HPP

#include <cstddef>
#include <cstdint>
#include <ostream>

#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))
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions api/utf16.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ namespace jule
std::tuple<jule::I32, jule::I32> utf16_encode_rune(jule::I32 r)
{
if (r < jule::UTF16_SURR_SELF || r > jule::UTF16_MAX_RUNE)
return std::make_tuple<jule::I32, jule::I32>(
return std::make_tuple(
jule::UTF16_REPLACEMENT_CHAR, jule::UTF16_REPLACEMENT_CHAR);

r -= jule::UTF16_SURR_SELF;
return std::make_tuple<jule::I32, jule::I32>(
return std::make_tuple(
jule::UTF16_SURR1 + (r >> 10) & 0x3ff, jule::UTF16_SURR2 + r & 0x3ff);
}

Expand Down
62 changes: 31 additions & 31 deletions api/utf8.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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::I32, jule::Int>(jule::UTF8_RUNE_ERROR, 0);
return std::make_tuple(jule::UTF8_RUNE_ERROR, 0);

const auto s0 = static_cast<jule::U8>(s[0]);
const jule::U8 x = jule::utf8_first[s0];
Expand All @@ -359,11 +359,11 @@ namespace jule
const auto sz = static_cast<std::size_t>(x & 7);
const struct jule::UTF8AcceptRange accept = jule::utf8_accept_ranges[x >> 4];
if (len < sz)
return std::make_tuple<jule::I32, std::size_t>(jule::UTF8_RUNE_ERROR, 1);
return std::make_tuple(jule::UTF8_RUNE_ERROR, 1);

const auto s1 = static_cast<jule::U8>(s[1]);
if (s1 < accept.lo || accept.hi < s1)
return std::make_tuple<jule::I32, std::size_t>(jule::UTF8_RUNE_ERROR, 1);
return std::make_tuple(jule::UTF8_RUNE_ERROR, 1);

if (sz <= 2)
return std::make_tuple<jule::I32, std::size_t>(
Expand All @@ -373,7 +373,7 @@ namespace jule

const auto s2 = static_cast<jule::U8>(s[2]);
if (s2 < jule::UTF8_LOCB || jule::UTF8_HICB < s2)
return std::make_tuple<jule::I32, std::size_t>(jule::UTF8_RUNE_ERROR, 1);
return std::make_tuple(jule::UTF8_RUNE_ERROR, 1);

if (sz <= 3)
return std::make_tuple<jule::I32, std::size_t>(
Expand All @@ -384,7 +384,7 @@ namespace jule

const auto s3 = static_cast<jule::U8>(s[3]);
if (s3 < jule::UTF8_LOCB || jule::UTF8_HICB < s3)
return std::make_tuple<jule::I32, std::size_t>(jule::UTF8_RUNE_ERROR, 1);
return std::make_tuple(jule::UTF8_RUNE_ERROR, 1);

return std::make_tuple((static_cast<jule::I32>(s0 & jule::UTF8_MASK4) << 18) |
(static_cast<jule::I32>(s1 & jule::UTF8_MASKX) << 12) |
Expand Down

0 comments on commit 8e15437

Please sign in to comment.