platform/base layer
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_H
|
||||||
|
#define CI2_H
|
||||||
|
|
||||||
|
#include "./platform/ci2_platform.h"
|
||||||
|
|
||||||
|
#endif // ci2.h
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_ASSERT_H
|
||||||
|
#define CI2_ASSERT_H
|
||||||
|
|
||||||
|
#include "../base/ci2_debug_trap.h"
|
||||||
|
#include "../base/ci2_func.h"
|
||||||
|
#include "../base/ci2_inline.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* Assert Fail */
|
||||||
|
static CI2_INLINE void
|
||||||
|
ci2_assert_fail(const char* expr,
|
||||||
|
const char* msg, /* may be NULL */
|
||||||
|
const char* file,
|
||||||
|
int line,
|
||||||
|
const char* func)
|
||||||
|
{
|
||||||
|
if (msg)
|
||||||
|
fprintf(stderr,
|
||||||
|
"\n[ASSERT FAILED]\n"
|
||||||
|
" Expression : %s\n"
|
||||||
|
" Message : %s\n"
|
||||||
|
" Location : %s:%d\n"
|
||||||
|
" Function : %s\n\n",
|
||||||
|
expr,
|
||||||
|
msg,
|
||||||
|
file,
|
||||||
|
line,
|
||||||
|
func);
|
||||||
|
else
|
||||||
|
fprintf(stderr,
|
||||||
|
"\n[ASSERT FAILED]\n"
|
||||||
|
" Expression : %s\n"
|
||||||
|
" Location : %s:%d\n"
|
||||||
|
" Function : %s\n\n",
|
||||||
|
expr,
|
||||||
|
file,
|
||||||
|
line,
|
||||||
|
func);
|
||||||
|
|
||||||
|
/* Flush so the message is visible before we halt */
|
||||||
|
fflush(stderr);
|
||||||
|
|
||||||
|
CI2_DEBUG_TRAP();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#define CI2_ASSERT(expr) \
|
||||||
|
do { \
|
||||||
|
if (!(expr)) { \
|
||||||
|
ci2_assert_fail(#expr, NULL, __FILE__, __LINE__, CI2_FUNC); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define CI2_ASSERT_MSG(expr, msg) \
|
||||||
|
do { \
|
||||||
|
if (!(expr)) { \
|
||||||
|
ci2_assert_fail(#expr, (msg), __FILE__, __LINE__, CI2_FUNC); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#else /* NDEBUG — strip all runtime checks */
|
||||||
|
|
||||||
|
#define CI2_ASSERT(expr) ((void)(expr))
|
||||||
|
#define CI2_ASSERT_MSG(expr, msg) ((void)(expr))
|
||||||
|
#endif /* NDEBUG */
|
||||||
|
|
||||||
|
#endif // ci2_assert.h
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_BASE_H
|
||||||
|
#define CI2_BASE_H
|
||||||
|
|
||||||
|
#include "ci2_compiler.h"
|
||||||
|
#include "ci2_os.h"
|
||||||
|
#include "ci2_thread.h"
|
||||||
|
#include "ci2_win_env.h"
|
||||||
|
|
||||||
|
#include "ci2_debug_trap.h"
|
||||||
|
#include "ci2_func.h"
|
||||||
|
#include "ci2_inline.h"
|
||||||
|
#include "ci2_static_assert.h"
|
||||||
|
|
||||||
|
#include "ci2_macros.h"
|
||||||
|
#include "ci2_syntax.h"
|
||||||
|
|
||||||
|
/* Here is where we abstract away the differnces between Operating Systems */
|
||||||
|
#if defined CI2_UNIX
|
||||||
|
#define CI2_INVALID_FD -1
|
||||||
|
typedef int ci2_fd;
|
||||||
|
typedef char ci2_sys_char;
|
||||||
|
|
||||||
|
#else // Windows:
|
||||||
|
|
||||||
|
#define CI2_INVALID_FD NULL
|
||||||
|
typedef HANDLE ci2_fd;
|
||||||
|
typedef wchar_t ci2_sys_char;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ci2_base.h
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_COMPILER_H
|
||||||
|
#define CI2_COMPILER_H
|
||||||
|
|
||||||
|
#if defined(__INTEL_LLVM_COMPILER)
|
||||||
|
#define CI2_INTEL_ICX
|
||||||
|
#elif defined(__GNUC__) && !defined(__clang__)
|
||||||
|
#define CI2_GCC
|
||||||
|
#elif defined(__clang__)
|
||||||
|
#define CI2_CLANG
|
||||||
|
#elif define(_MSC_VER) && !defined(__clang__)
|
||||||
|
#define CI2_MSVC
|
||||||
|
#else
|
||||||
|
#error "Compiler is unkown and unsupported."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ci2_compiler.h
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_DEBUG_TRAP_H
|
||||||
|
#define CI2_DEBUG_TRAP_H
|
||||||
|
|
||||||
|
/* Use __has_builtin if available (Clang and newer GCC). */
|
||||||
|
#if defined(__has_builtin)
|
||||||
|
/* Check builtins in preferred order */
|
||||||
|
#if __has_builtin(__builtin_debugtrap)
|
||||||
|
#define CI2_DEBUG_TRAP() __builtin_debugtrap()
|
||||||
|
#elif __has_builtin(__builtin_trap)
|
||||||
|
#define CI2_DEBUG_TRAP() __builtin_trap()
|
||||||
|
#elif __has_builtin(__builtin_break)
|
||||||
|
#define CI2_DEBUG_TRAP() __builtin_break()
|
||||||
|
#endif
|
||||||
|
#elif defined(_MSC_VER) || defined(__INTEL__LLVM_COMPILER)
|
||||||
|
#define CI2_DEBUG_TRAP() __debugbreak()
|
||||||
|
#else
|
||||||
|
#define CI2_DEBUG_TRAP() (*(volatile int*)0 = 0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ci2_debug_trap.h
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_FUNC_H
|
||||||
|
#define CI2_FUNC_H
|
||||||
|
|
||||||
|
/* Current __func__ */
|
||||||
|
#if defined(__FUNC__)
|
||||||
|
#define CI2_FUNC __FUNCTION__
|
||||||
|
#else
|
||||||
|
#define CI2_FUNC __func__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ci2_func.h
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_INLINE_H
|
||||||
|
#define CI2_INLINE_H
|
||||||
|
|
||||||
|
/* Force Inline */
|
||||||
|
#if defined(_MSC_VER) || defined(__INTEL__LLVM_COMPILER)
|
||||||
|
#define CI2_INLINE __forceinline
|
||||||
|
#elif defined(__GNUC__) || defined(__clang__)
|
||||||
|
#define CI2_INLINE __attribute__((always_inline)) inline
|
||||||
|
#else
|
||||||
|
#define CI2_INLINE inline
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ci2_inline.h
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_MACROS_H
|
||||||
|
#define CI2_MACROS_H
|
||||||
|
|
||||||
|
#define UNUSED(x) (void)(x)
|
||||||
|
#define STR2(s) #s
|
||||||
|
#define STR(s) STR2(s)
|
||||||
|
|
||||||
|
#define U8_MIN 0u
|
||||||
|
#define U8_MAX 0xffu
|
||||||
|
#define I8_MIN (-0x7f - 1)
|
||||||
|
#define I8_MAX 0x7f
|
||||||
|
|
||||||
|
#define U16_MIN 0u
|
||||||
|
#define U16_MAX 0xffffu
|
||||||
|
#define I16_MIN (-0x7fff - 1)
|
||||||
|
#define I16_MAX 0x7fff
|
||||||
|
|
||||||
|
#define U32_MIN 0u
|
||||||
|
#define U32_MAX 0xffffffffu
|
||||||
|
#define I32_MIN (-0x7fffffff - 1)
|
||||||
|
#define I32_MAX 0x7fffffff
|
||||||
|
|
||||||
|
#define U64_MIN 0ull
|
||||||
|
#define U64_MAX 0xffffffffffffffffull
|
||||||
|
#define I64_MIN (-0x7fffffffffffffffll - 1)
|
||||||
|
#define I64_MAX 0x7fffffffffffffffll
|
||||||
|
|
||||||
|
#define F32_MIN 1.17549435e-38f
|
||||||
|
#define F32_MAX 3.40282347e+38f
|
||||||
|
|
||||||
|
#define F64_MIN 2.2250738585072014e-308
|
||||||
|
#define F64_MAX 1.7976931348623157e+308
|
||||||
|
|
||||||
|
#define PI 3.14159265
|
||||||
|
#define RAD2DEG(x) ((x) / PI * 180)
|
||||||
|
#define DEG2RAD(x) ((x) * PI / 180)
|
||||||
|
#define ALIGNB(x, align) (((x) + ((align) - 1)) & ~((align) - 1))
|
||||||
|
#define ALIGN(x, align) ((((x) + ((align) - 1)) / (align)) * (align))
|
||||||
|
#define FLOORB(x, align) ((x) & ~((align) - 1))
|
||||||
|
#define FLOOR(x, align) (((x) / (align)) * (align))
|
||||||
|
#define CEILB(x, align) ALIGNB(x, align)
|
||||||
|
#define CEIL(x, align) ALIGN(x, align)
|
||||||
|
#define CLIP(x, min, max) \
|
||||||
|
(((x) < (min)) ? (min) : (((x) > (max)) ? (max) : (x)))
|
||||||
|
#define UCLIP(x, max) (((x) > (max)) ? (max) : (x))
|
||||||
|
#define LCLIP(x, min) (((x) < (min)) ? (min) : (x))
|
||||||
|
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||||
|
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||||
|
#define ABS(x) (((x) < 0) ? -(x) : (x))
|
||||||
|
#define DIFF(a, b) ABS((a) - (b))
|
||||||
|
#define IS_NAN(x) ((x) != (x))
|
||||||
|
#define IMPLIES(x, y) (!(x) || (y))
|
||||||
|
#define COMPARE(x, y) (((x) > (y)) - ((x) < (y)))
|
||||||
|
#define SIGN(x) COMPARE(x, 0)
|
||||||
|
#define IS_ODD(num) ((num) & 1)
|
||||||
|
#define IS_EVEN(num) (!IS_ODD((num)))
|
||||||
|
#define IS_BETWEEN(n, L, H) ((unsigned char)((n) >= (L) && (n) <= (H)))
|
||||||
|
|
||||||
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
||||||
|
#define SET(d, n, v) \
|
||||||
|
do { \
|
||||||
|
size_t i_, n_; \
|
||||||
|
for (n_ = (n), i_ = 0; n_ > 0; --n_, ++i_) \
|
||||||
|
(d)[i_] = (v); \
|
||||||
|
} while (0)
|
||||||
|
#define ZERO(d, n) SET(d, n, 0)
|
||||||
|
#define SWAP(a, b) \
|
||||||
|
do { \
|
||||||
|
a ^= b; \
|
||||||
|
b ^= a; \
|
||||||
|
a ^= b; \
|
||||||
|
} while (0)
|
||||||
|
#define SORT(a, b) \
|
||||||
|
do { \
|
||||||
|
if ((a) > (b)) \
|
||||||
|
SWAP((a), (b)); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#endif // ci2_macros.h
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_OS_H
|
||||||
|
#define CI2_OS_H
|
||||||
|
|
||||||
|
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||||
|
/* Entire windows platform */
|
||||||
|
#define CI2_WIN_APIVER 0x0600 // Vista
|
||||||
|
#define NOMINMAX // Don't define min/max macros
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS // No unsafe C warnings
|
||||||
|
#define _CRT_RAND_S // TODO
|
||||||
|
#define OEMRESOURCE // GUI must be before windows.h
|
||||||
|
#include <windows.h> // haha
|
||||||
|
#define CI2_WINDOWS
|
||||||
|
|
||||||
|
#ifdef _WIN64
|
||||||
|
/* Windows (64-bit only) */
|
||||||
|
#define CI2_WINDOWS_64
|
||||||
|
#else
|
||||||
|
/* Windows (32-bit only) */
|
||||||
|
#define CI2_WINDOWS_32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif __APPLE__
|
||||||
|
#define CI2_UNIX
|
||||||
|
#define CI2_APPLE
|
||||||
|
#include <TargetConditionals.h>
|
||||||
|
#if TARGET_IPHONE_SIMULATOR
|
||||||
|
// iOS, tvOS, or watchOS Simulator
|
||||||
|
#define CI2_IOS
|
||||||
|
#elif TARGET_OS_MACCATALYST
|
||||||
|
// Mac's Catalyst (ports iOS API into Mac, like UIKit).
|
||||||
|
#define CI2_IOS
|
||||||
|
#elif TARGET_OS_IPHONE
|
||||||
|
// iOS, tvOS, or watchOS device
|
||||||
|
#define CI2_IOS
|
||||||
|
#elif TARGET_OS_MAC
|
||||||
|
// Other kinds of Apple platforms
|
||||||
|
#define CI2_OSX
|
||||||
|
#else
|
||||||
|
#error "Unknown Apple platform"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif __ANDROID__
|
||||||
|
#define CI2_UNIX
|
||||||
|
#define CI2_ANDROID
|
||||||
|
|
||||||
|
#elif __linux__
|
||||||
|
#define CI2_UNIX
|
||||||
|
|
||||||
|
#elif __unix__ // TODO BSD Variants
|
||||||
|
#define CI2_UNIX
|
||||||
|
|
||||||
|
#elif defined(_POSIX_VERSION)
|
||||||
|
#define CI2_POSIX
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "Unknown and unsupported operating system."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ci2_os.h
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_STATIC_ASSERT_H
|
||||||
|
#define CI2_STATIC_ASSERT_H
|
||||||
|
|
||||||
|
/* Static Asserts */
|
||||||
|
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
|
||||||
|
/* C11 */
|
||||||
|
#define CI2_STATIC_ASSERT(expr) _Static_assert((expr), #expr)
|
||||||
|
#else
|
||||||
|
/* Abuse a typedef of a negative-size array */
|
||||||
|
#define CI2_STATIC_ASSERT(expr) typedef char _static_assert_[(expr) ? 1 : -1]
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ci2_static_assert.h
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_SYNTAX_H
|
||||||
|
#define CI2_SYNTAX_H
|
||||||
|
|
||||||
|
/* Floating Points */
|
||||||
|
typedef float ci2_f32; // IEEE 754
|
||||||
|
typedef double ci2_f64; // IEE 754
|
||||||
|
|
||||||
|
/* Characters */
|
||||||
|
typedef signed char ci2_char; // [−127, +127]
|
||||||
|
typedef unsigned char ci2_uchar; // [0, 255]
|
||||||
|
typedef unsigned char ci2_byte; // [0, 255]
|
||||||
|
typedef unsigned char* ci2_bytes; // Pointer
|
||||||
|
|
||||||
|
/* Integers */
|
||||||
|
typedef signed short ci2_short; // [−32,767, 32,767]
|
||||||
|
typedef unsigned short ci2_ushort; // [0, 65,535]
|
||||||
|
typedef signed int ci2_int; // [−32,767, 32,767]
|
||||||
|
typedef unsigned int ci2_uint; // [0, 65,535]
|
||||||
|
typedef signed long int ci2_long; // [−2,147,483,647, 2,147,483,647]
|
||||||
|
typedef unsigned long int ci2_ulong; // [0, 4,294,967,295]
|
||||||
|
|
||||||
|
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L // C99
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
// −9223372036854775807
|
||||||
|
typedef unsigned long long int ci2_ull; // +9223372036854775807 range.
|
||||||
|
typedef signed long long int ci2_ll; //[0, 18446744073709551615] range.
|
||||||
|
|
||||||
|
typedef int8_t i8;
|
||||||
|
typedef int16_t i16;
|
||||||
|
typedef int32_t i32;
|
||||||
|
typedef int64_t i64;
|
||||||
|
|
||||||
|
typedef uint8_t u8;
|
||||||
|
typedef uint16_t u16;
|
||||||
|
typedef uint32_t u32;
|
||||||
|
typedef uint64_t u64;
|
||||||
|
|
||||||
|
typedef uintptr_t uptr;
|
||||||
|
typedef ptrdiff_t size;
|
||||||
|
typedef size_t usize;
|
||||||
|
|
||||||
|
#endif // C99
|
||||||
|
|
||||||
|
#endif // ci2_syntax.h
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_THREAD_H
|
||||||
|
#define CI2_THREAD_H
|
||||||
|
|
||||||
|
#if !defined(ci2_thread_local)
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER >= 1300
|
||||||
|
#define ci2_thread_local __declspec(thread)
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#define ci2_thread_local __thread
|
||||||
|
#else
|
||||||
|
#define ci2_thread_local thread_local
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ci2_thread.h
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_WIN_ENV_H
|
||||||
|
#define CI2_WIN_ENV_H
|
||||||
|
|
||||||
|
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||||
|
#if defined __MINGW32__ || defined __MINGW64__
|
||||||
|
#define CI2_WIN_ENV
|
||||||
|
#define CI2_MINGW
|
||||||
|
#elif defined __CYGWIN__
|
||||||
|
#define CI2_WIN_ENV
|
||||||
|
#define CI2_CYGWIN
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ci2_win_env.h
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#ifndef CI2_PLATFORM_H
|
||||||
|
#define CI2_PLATFORM_H
|
||||||
|
|
||||||
|
#include "./assert/ci2_assert.h"
|
||||||
|
#include "./base/ci2_base.h"
|
||||||
|
|
||||||
|
/* No name mangling for declarations---------------------------------------- */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* CI2_EXTERN: plain extern with C++ aware linkage token for macros if needed */
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
#define CI2_EXTERN extern "C"
|
||||||
|
#else
|
||||||
|
#define CI2_EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* CI2_API: platform/compiler-aware import/export/visibility */
|
||||||
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||||
|
#if defined(CI2_BUILD_DLL)
|
||||||
|
#define CI2_API CI2_EXTERN __declspec(dllexport)
|
||||||
|
#elif defined(CI2_USE_DLL)
|
||||||
|
#define CI2_API CI2_EXTERN __declspec(dllimport)
|
||||||
|
#else
|
||||||
|
#define CI2_API CI2_EXTERN
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
/* Non-Windows: use visibility if supported */
|
||||||
|
#if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_LLVM_COMPILER)
|
||||||
|
#if defined(CI2_BUILD_DLL)
|
||||||
|
#define CI2_API CI2_EXTERN __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
#define CI2_API CI2_EXTERN
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define CI2_API CI2_EXTERN
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* CI2_DEF: internal vs external linkage */
|
||||||
|
#ifndef CI2_DEF
|
||||||
|
#ifdef CI2_STATIC
|
||||||
|
#define CI2_DEF static
|
||||||
|
#else
|
||||||
|
#define CI2_DEF CI2_API
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CI2_SUCCESS 0
|
||||||
|
#define CI2_FAILURE -1
|
||||||
|
|
||||||
|
#define CI2_TRUE 1
|
||||||
|
#define CI2_FALSE 0
|
||||||
|
|
||||||
|
#define CI2_SIZE(x) (ptrdiff_t)sizeof(x)
|
||||||
|
#define CI2_COUNT(a) (sizeof(a) / sizeof(*(a)))
|
||||||
|
#define CI2_LEN(s) (countof(s) - 1)
|
||||||
|
#define CI2_KB(x) ((x) * (size_t)(1024))
|
||||||
|
#define CI2_MB(x) (CI2_KB(x) * (size_t)(1024))
|
||||||
|
#define CI2_GB(x) (CI2_MB(x) * (size_t)(1024))
|
||||||
|
#define CI2_TB(x) (CI2_GB(x) * (size_t)(1024))
|
||||||
|
|
||||||
|
CI2_API ci2_thread_local int ci2_errno;
|
||||||
|
CI2_API int* ci2_errno_location(void);
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif // c++
|
||||||
|
|
||||||
|
#endif // ci2_platform.h
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#define DEBUG
|
||||||
|
#include "../include/ci2.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <limits.h> /* INT_MAX, CHAR_BIT — C standard */
|
||||||
|
#include <float.h> /* FLT_MANT_DIG — C standard */
|
||||||
|
int main(int argc, char *argv[]){
|
||||||
|
(void) argc;
|
||||||
|
(void) argv;
|
||||||
|
|
||||||
|
/* Fundamental type sizes that almost all C code silently assumes. */
|
||||||
|
CI2_STATIC_ASSERT(CHAR_BIT == 8);
|
||||||
|
CI2_STATIC_ASSERT(sizeof(char) == 1);
|
||||||
|
CI2_STATIC_ASSERT(sizeof(short) == 2);
|
||||||
|
CI2_STATIC_ASSERT(sizeof(int) == 4);
|
||||||
|
CI2_STATIC_ASSERT(sizeof(float) == 4);
|
||||||
|
CI2_STATIC_ASSERT(sizeof(double) == 8);
|
||||||
|
|
||||||
|
/* Pointer and size_t width — catches ILP64 oddities. */
|
||||||
|
CI2_STATIC_ASSERT(sizeof(void *) == sizeof(size_t));
|
||||||
|
|
||||||
|
/* Fixed-width types from <stdint.h> */
|
||||||
|
CI2_STATIC_ASSERT(sizeof(uint8_t) == 1);
|
||||||
|
CI2_STATIC_ASSERT(sizeof(uint16_t) == 2);
|
||||||
|
CI2_STATIC_ASSERT(sizeof(uint32_t) == 4);
|
||||||
|
CI2_STATIC_ASSERT(sizeof(uint64_t) == 8);
|
||||||
|
|
||||||
|
CI2_STATIC_ASSERT(sizeof(int8_t) == 1);
|
||||||
|
CI2_STATIC_ASSERT(sizeof(int16_t) == 2);
|
||||||
|
CI2_STATIC_ASSERT(sizeof(int32_t) == 4);
|
||||||
|
CI2_STATIC_ASSERT(sizeof(int64_t) == 8);
|
||||||
|
|
||||||
|
/* IEEE-754 single precision: 24 significand bits. */
|
||||||
|
CI2_STATIC_ASSERT(FLT_MANT_DIG == 24);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#define DEBUG
|
||||||
|
#include "../include/ci2.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* Platform-specific verification headers */
|
||||||
|
#if defined(CI2_WINDOWS)
|
||||||
|
#include <windows.h> /* GetSystemInfo, SYSTEM_INFO */
|
||||||
|
#elif defined(CI2_UNIX)
|
||||||
|
#include <sys/utsname.h>/* uname() — POSIX */
|
||||||
|
#include <unistd.h> /* sysconf, _SC_* constants — POSIX */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
|
|
||||||
|
#if defined(CI2_WINDOWS)
|
||||||
|
printf(" Detected platform : Windows\n");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GetSystemInfo() is a Win32 API that fills SYSTEM_INFO.
|
||||||
|
* If _WIN32 were wrong this wouldn't compile or link.
|
||||||
|
*/
|
||||||
|
SYSTEM_INFO si;
|
||||||
|
GetSystemInfo(&si);
|
||||||
|
|
||||||
|
printf(" Page size : %lu bytes\n", (unsigned long)si.dwPageSize);
|
||||||
|
printf(" Processor count : %lu\n", (unsigned long)si.dwNumberOfProcessors);
|
||||||
|
printf(" Processor arch : %u\n", (unsigned)si.wProcessorArchitecture);
|
||||||
|
|
||||||
|
CI2_ASSERT(si.dwPageSize > 0);
|
||||||
|
CI2_ASSERT(si.dwNumberOfProcessors > 0);
|
||||||
|
|
||||||
|
#elif defined(CI2_UNIX)
|
||||||
|
/*
|
||||||
|
* uname() fills a struct utsname with kernel name, release, machine, etc.
|
||||||
|
* This is a POSIX function — available on Linux, macOS, and all BSDs.
|
||||||
|
* It won't compile on Windows, proving our platform guard is correct.
|
||||||
|
*/
|
||||||
|
struct utsname uts;
|
||||||
|
int ret = uname(&uts);
|
||||||
|
CI2_ASSERT(ret == 0);
|
||||||
|
|
||||||
|
printf(" Detected platform : Unix-like\n");
|
||||||
|
printf(" OS / sysname : %s\n", uts.sysname);
|
||||||
|
printf(" Kernel release : %s\n", uts.release);
|
||||||
|
printf(" Machine arch : %s\n", uts.machine);
|
||||||
|
printf(" Node name : %s\n", uts.nodename);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* sysconf() is another POSIX function.
|
||||||
|
* _SC_PAGESIZE and _SC_NPROCESSORS_ONLN are available on Linux & macOS.
|
||||||
|
*/
|
||||||
|
long page_size = sysconf(_SC_PAGESIZE);
|
||||||
|
long n_cpus = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
|
||||||
|
printf(" Page size : %ld bytes\n", page_size);
|
||||||
|
printf(" CPUs online : %ld\n", n_cpus);
|
||||||
|
|
||||||
|
CI2_ASSERT(page_size > 0);
|
||||||
|
CI2_ASSERT(n_cpus > 0);
|
||||||
|
|
||||||
|
/* Sanity: page size is always a power of two */
|
||||||
|
CI2_ASSERT((page_size & (page_size - 1)) == 0);
|
||||||
|
|
||||||
|
#if defined(CI2_LINUX)
|
||||||
|
printf(" Sub-platform : Linux\n");
|
||||||
|
CI2_ASSERT(strlen(uts.sysname) > 0);
|
||||||
|
#elif defined(CI2_MACOS)
|
||||||
|
printf(" Sub-platform : macOS\n");
|
||||||
|
CI2_ASSERT(strlen(uts.sysname) > 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
printf(" [FAIL] No platform macro was defined!\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#define DEBUG
|
||||||
|
#include "../include/ci2.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]){
|
||||||
|
(void) argc;
|
||||||
|
(void) argv;
|
||||||
|
|
||||||
|
#if defined(CI2_INTEL_ICX)
|
||||||
|
printf(" Detected compiler : INTEL-IXC\n");
|
||||||
|
printf(" __INTEL_LLVM_COMPILER VER: %d\n", __INTEL_LLVM_COMPILER);
|
||||||
|
CI2_ASSERT(__INTEL_LLVM_COMPILER > 0);
|
||||||
|
#elif defined(CI2_GCC)
|
||||||
|
printf(" Detected compiler : GCC\n");
|
||||||
|
printf(" GCC __VERSION__: %s\n", __VERSION__);
|
||||||
|
CI2_ASSERT(strlen(__VERSION__) > 0);
|
||||||
|
#elif defined(CI2_CLANG)
|
||||||
|
printf(" Detected compiler : CLANG\n");
|
||||||
|
printf(" __clang_version__: %s\n", __clang_version__);
|
||||||
|
CI2_ASSERT(strlen(__clang_version__) > 0);
|
||||||
|
#elif defined(CI2_MSVC)
|
||||||
|
printf(" Detected compiler : MSVC\n");
|
||||||
|
printf(" _MSC_VER : %d\n", _MSC_VER);
|
||||||
|
CI2_ASSERT(_MSC_VER > 0);
|
||||||
|
|
||||||
|
#else
|
||||||
|
printf(" [FAIL] No compiler macro was defined!\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
/* - | Copyright | ------------------------------------------------------------
|
||||||
|
Copyright (c) 2026 Randy Jordan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
* --------------------------------------------------------------------------*/
|
||||||
|
#define DEBUG
|
||||||
|
#include "../include/ci2.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h> /* bool, true, false — C99 */
|
||||||
|
#include <string.h> /* strcmp — C standard */
|
||||||
|
static void test_assert_passing(void){
|
||||||
|
/* Basic truthy values */
|
||||||
|
CI2_ASSERT(1);
|
||||||
|
CI2_ASSERT(1 == 1);
|
||||||
|
|
||||||
|
/* Pointer non-null */
|
||||||
|
const char *str = "hello";
|
||||||
|
CI2_ASSERT(str != NULL);
|
||||||
|
|
||||||
|
/* Arithmetic */
|
||||||
|
int x = 42;
|
||||||
|
CI2_ASSERT(x > 0);
|
||||||
|
CI2_ASSERT(x * 2 == 84);
|
||||||
|
|
||||||
|
/* CI2_ASSERT_MSG variants */
|
||||||
|
CI2_ASSERT_MSG(x == 42, "x must be 42");
|
||||||
|
CI2_ASSERT_MSG(sizeof(int) == 4, "int must be 4 bytes on this platform");
|
||||||
|
|
||||||
|
/* Boolean */
|
||||||
|
bool flag = true;
|
||||||
|
CI2_ASSERT(flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void test_assert_failing(void){
|
||||||
|
printf(" Triggering CI2_ASSERT(0) failure now...\n");
|
||||||
|
fflush(stdout);
|
||||||
|
CI2_ASSERT(0); /* <-- should break/trap here */
|
||||||
|
/* Should never reach here */
|
||||||
|
printf(" [FAIL] Execution continued past a failing CI2_ASSERT!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_assert_msg_failing(void){
|
||||||
|
printf("CI2_ASSERT_MSG — Deliberate Failure (triggering a debug break...)\n");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
CI2_ASSERT_MSG(0, "This failure is intentional — testing the message path");
|
||||||
|
|
||||||
|
printf(" [FAIL] Execution continued past a failing CI2_ASSERT_MSG!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_ndebug_status(void){
|
||||||
|
printf("NDEBUG / Release Mode");
|
||||||
|
|
||||||
|
#ifdef NDEBUG
|
||||||
|
printf(" NDEBUG is DEFINED — asserts are compiled out.\n");
|
||||||
|
CI2_ASSERT(0); /* harmless in release */
|
||||||
|
printf(" Confirmed: CI2_ASSERT(0) was a no-op.\n");
|
||||||
|
#else
|
||||||
|
printf(" NDEBUG is NOT defined — asserts are active (debug build).\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]){
|
||||||
|
(void) argc;
|
||||||
|
(void) argv;
|
||||||
|
/* Determine whether the user wants to trigger a deliberate failure */
|
||||||
|
bool run_fail = false;
|
||||||
|
bool run_fail_msg = false;
|
||||||
|
|
||||||
|
for (int i = 1; i < argc; i++) {
|
||||||
|
if (strcmp(argv[i], "--fail") == 0) run_fail = true;
|
||||||
|
if (strcmp(argv[i], "--fail-msg") == 0) run_fail_msg = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- Run the safe tests --- */
|
||||||
|
test_assert_passing();
|
||||||
|
test_ndebug_status();
|
||||||
|
|
||||||
|
/* --- Optional deliberate-failure tests --- */
|
||||||
|
if (run_fail) test_assert_failing();
|
||||||
|
if (run_fail_msg) test_assert_msg_failing();
|
||||||
|
|
||||||
|
|
||||||
|
if (!run_fail && !run_fail_msg) {
|
||||||
|
printf("Tip: run with --fail or --fail-msg to test the");
|
||||||
|
printf(" debug-break path (attach a debugger first).\n");
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user