IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1
11
12
13#pragma once
14
15
16// C++
17#include <cstddef>
18#include <cstdint>
19#include <cstdlib>
20#include <type_traits>
21#include <utility>
22
23
24// OS namespace
25namespace igros {
26
27
33
34 // Signed integers
35 using igros_sbyte_t = std::int8_t;
36 using igros_sword_t = std::int16_t;
37 using igros_sdword_t = std::int32_t;
38 using igros_squad_t = std::int64_t;
39
40 // Unsigned integers
41 using igros_byte_t = std::uint8_t;
42 using igros_word_t = std::uint16_t;
43 using igros_dword_t = std::uint32_t;
44 using igros_quad_t = std::uint64_t;
45
46 // Floating-point reals
47 using igros_real32_t = float;
48 using igros_real64_t = double;
49
50 // Size types
51 using igros_usize_t = std::size_t;
52 using igros_ssize_t = std::ptrdiff_t;
53
55 using igros_pointer_t = std::add_pointer_t<void>;
56
57
59
60
66
67 // Literals are evaluated by compiler only: no runtime code to cover
68 // GCOVR_EXCL_START
69
73 namespace literal {
74
82 template<class T>
83 [[nodiscard]]
84 consteval auto make(const unsigned long long value) noexcept -> T {
85 if (!std::in_range<T>(value)) {
86 std::abort(); // IgrOS: integer literal doesn't fit its type
87 }
88 return static_cast<T>(value);
89 }
90
91 } // namespace literal
92
100 [[nodiscard]]
101 consteval auto operator""_i8(const unsigned long long value) noexcept -> igros_sbyte_t {
102 // Checked value
103 return literal::make<igros_sbyte_t>(value);
104 }
105
113 [[nodiscard]]
114 consteval auto operator""_i16(const unsigned long long value) noexcept -> igros_sword_t {
115 // Checked value
116 return literal::make<igros_sword_t>(value);
117 }
118
126 [[nodiscard]]
127 consteval auto operator""_i32(const unsigned long long value) noexcept -> igros_sdword_t {
128 // Checked value
129 return literal::make<igros_sdword_t>(value);
130 }
131
139 [[nodiscard]]
140 consteval auto operator""_i64(const unsigned long long value) noexcept -> igros_squad_t {
141 // Checked value
142 return literal::make<igros_squad_t>(value);
143 }
144
145
153 [[nodiscard]]
154 consteval auto operator""_u8(const unsigned long long value) noexcept -> igros_byte_t {
155 // Checked value
156 return literal::make<igros_byte_t>(value);
157 }
158
166 [[nodiscard]]
167 consteval auto operator""_u16(const unsigned long long value) noexcept -> igros_word_t {
168 // Checked value
169 return literal::make<igros_word_t>(value);
170 }
171
179 [[nodiscard]]
180 consteval auto operator""_u32(const unsigned long long value) noexcept -> igros_dword_t {
181 // Checked value
182 return literal::make<igros_dword_t>(value);
183 }
184
192 [[nodiscard]]
193 consteval auto operator""_u64(const unsigned long long value) noexcept -> igros_quad_t {
194 // Checked value
195 return literal::make<igros_quad_t>(value);
196 }
197
198
206 [[nodiscard]]
207 consteval auto operator""_f32(const unsigned long long value) noexcept -> igros_real32_t {
208 // Return value
209 return static_cast<igros_real32_t>(value);
210 }
211
219 [[nodiscard]]
220 consteval auto operator""_f32(const long double value) noexcept -> igros_real32_t {
221 // Return value
222 return static_cast<igros_real32_t>(value);
223 }
224
232 [[nodiscard]]
233 consteval auto operator""_f64(const unsigned long long value) noexcept -> igros_real64_t {
234 // Return value
235 return static_cast<igros_real64_t>(value);
236 }
237
245 [[nodiscard]]
246 consteval auto operator""_f64(const long double value) noexcept -> igros_real64_t {
247 // Return value
248 return static_cast<igros_real64_t>(value);
249 }
250
251
259 [[nodiscard]]
260 consteval auto operator""_usize(const unsigned long long value) noexcept -> igros_usize_t {
261 // Checked value
262 return literal::make<igros_usize_t>(value);
263 }
264
272 [[nodiscard]]
273 consteval auto operator""_ssize(const unsigned long long value) noexcept -> igros_ssize_t {
274 // Checked value
275 return literal::make<igros_ssize_t>(value);
276 }
277
278 // GCOVR_EXCL_STOP
279
281
282
283} // namespace igros
284
std::uint16_t igros_word_t
16-bit unsigned integer
Definition types.hpp:42
float igros_real32_t
32-bit floating point
Definition types.hpp:47
std::int64_t igros_squad_t
64-bit signed integer
Definition types.hpp:38
std::size_t igros_usize_t
Unsigned size.
Definition types.hpp:51
std::uint8_t igros_byte_t
8-bit unsigned integer
Definition types.hpp:41
std::uint32_t igros_dword_t
32-bit unsigned integer
Definition types.hpp:43
double igros_real64_t
64-bit floating point
Definition types.hpp:48
std::add_pointer_t< void > igros_pointer_t
Common pointer type.
Definition types.hpp:55
std::int8_t igros_sbyte_t
8-bit signed integer
Definition types.hpp:35
std::ptrdiff_t igros_ssize_t
Signed size (difference).
Definition types.hpp:52
std::int16_t igros_sword_t
16-bit signed integer
Definition types.hpp:36
std::int32_t igros_sdword_t
32-bit signed integer
Definition types.hpp:37
std::uint64_t igros_quad_t
64-bit unsigned integer
Definition types.hpp:44
Integer literals range check (operators are consteval, so a call.
Definition types.hpp:73
consteval auto make(const unsigned long long value) noexcept -> T
Integer literal of given type.
Definition types.hpp:84
IgrOS kernel: common types and literals.