organizing, resolving dependencies

This commit is contained in:
2025-02-01 14:28:12 -05:00
parent 1d0045b759
commit ffaa2ca19f
45 changed files with 387 additions and 18 deletions
+13
View File
@@ -0,0 +1,13 @@
#if MD_INTELLISENSE_DIRECTIVES
#pragma once
#endif
#if defined( _WIN64 ) || defined( __x86_64__ ) || defined( _M_X64 ) || defined( __64BIT__ ) || defined( __powerpc64__ ) || defined( __ppc64__ ) || defined( __aarch64__ )
# ifndef MD_ARCH_64_BIT
# define MD_ARCH_64_BIT 1
# endif
#else
# ifndef MD_ARCH_32_BIT
# define MD_ARCH_32_BIT 1
# endif
#endif
+128
View File
@@ -0,0 +1,128 @@
#ifdef MD_INTELLISENSE_DIRECTIVES
#pragma once
#include "macros.h"
#endif
#pragma region Basic Types
#define MD_U8_MIN 0u
#define MD_U8_MAX 0xffu
#define MD_I8_MIN ( -0x7f - 1 )
#define MD_I8_MAX 0x7f
#define MD_U16_MIN 0u
#define MD_U16_MAX 0xffffu
#define MD_I16_MIN ( -0x7fff - 1 )
#define MD_I16_MAX 0x7fff
#define MD_U32_MIN 0u
#define MD_U32_MAX 0xffffffffu
#define MD_I32_MIN ( -0x7fffffff - 1 )
#define MD_I32_MAX 0x7fffffff
#define MD_U64_MIN 0ull
#define MD_U64_MAX 0xffffffffffffffffull
#define MD_I64_MIN ( -0x7fffffffffffffffll - 1 )
#define MD_I64_MAX 0x7fffffffffffffffll
#if defined( MD_ARCH_32_BIT )
# define MD_USIZE_MIN GEN_U32_MIN
# define MD_USIZE_MAX GEN_U32_MAX
# define MD_ISIZE_MIN GEN_S32_MIN
# define MD_ISIZE_MAX GEN_S32_MAX
#elif defined( MD_ARCH_64_BIT )
# define MD_USIZE_MIN GEN_U64_MIN
# define MD_USIZE_MAX GEN_U64_MAX
# define MD_ISIZE_MIN GEN_I64_MIN
# define MD_ISIZE_MAX GEN_I64_MAX
#else
# error Unknown architecture size. This library only supports 32 bit and 64 bit architectures.
#endif
#define MD_F32_MIN 1.17549435e-38f
#define MD_F32_MAX 3.40282347e+38f
#define MD_F64_MIN 2.2250738585072014e-308
#define MD_F64_MAX 1.7976931348623157e+308
#if defined( MD_COMPILER_MSVC )
# if _MSC_VER < 1300
typedef unsigned char U8;
typedef signed char S8;
typedef unsigned short U16;
typedef signed short S16;
typedef unsigned int U32;
typedef signed int S32;
# else
typedef unsigned __int8 U8;
typedef signed __int8 S8;
typedef unsigned __int16 U16;
typedef signed __int16 S16;
typedef unsigned __int32 U32;
typedef signed __int32 S32;
# endif
typedef unsigned __int64 U64;
typedef signed __int64 S64;
#else
# include <stdint.h>
typedef uint8_t U8;
typedef int8_t S8;
typedef uint16_t U16;
typedef int16_t S16;
typedef uint32_t U32;
typedef int32_t S32;
typedef uint64_t U64;
typedef int64_t S64;
#endif
typedef struct U128 U128;
struct U128 {
U64 data[2];
};
static_assert( sizeof( U8 ) == sizeof( S8 ), "sizeof(U8) != sizeof(S8)" );
static_assert( sizeof( U16 ) == sizeof( S16 ), "sizeof(U16) != sizeof(sS6)" );
static_assert( sizeof( U32 ) == sizeof( S32 ), "sizeof(U32) != sizeof(sS2)" );
static_assert( sizeof( U64 ) == sizeof( S64 ), "sizeof(U64) != sizeof(sS4)" );
static_assert( sizeof( U8 ) == 1, "sizeof(U8) != 1" );
static_assert( sizeof( U16 ) == 2, "sizeof(U16) != 2" );
static_assert( sizeof( U32 ) == 4, "sizeof(U32) != 4" );
static_assert( sizeof( U64 ) == 8, "sizeof(U64) != 8" );
typedef size_t USIZE;
typedef ptrdiff_t SSIZE;
static_assert( sizeof( USIZE ) == sizeof( SSIZE ), "sizeof(USIZE) != sizeof(SSIZE)" );
// NOTE: (u)zpl_intptr is only here for semantic reasons really as this library will only support 32/64 bit OSes.
#if defined( _WIN64 )
typedef signed __int64 SPTR;
typedef unsigned __int64 UPTR;
#elif defined( _WIN32 )
// NOTE; To mark types changing their size, e.g. zpl_intptr
# ifndef _W64
# if ! defined( __midl ) && ( defined( _X86_ ) || defined( _M_IX86 ) ) && _MSC_VER >= 1300
# define _W64 __w64
# else
# define _W64
# endif
# endifk
typedef _W64 signed int SPTR;
typedef _W64 unsigned int UPTR;
#else
typedef uintptr_t UPTR;
typedef intptr_t SPTR;
#endif
static_assert( sizeof( UPTR ) == sizeof( SPTR ), "sizeof(UPTR) != sizeof(SPTR)" );
typedef float F32;
typedef double F64;
static_assert( sizeof( F32 ) == 4, "sizeof(F32) != 4" );
static_assert( sizeof( F64 ) == 8, "sizeof(F64) != 8" );
typedef S8 B8;
typedef S16 B16;
typedef S32 B32;
+65
View File
@@ -0,0 +1,65 @@
#if MD_INTELLISENSE_DIRECTIVES
#pragma once
#endif
#pragma region Platform Compiler
#if defined( _MSC_VER )
# pragma message("Detected MSVC")
// # define MD_COMPILER_CLANG 0
# define MD_COMPILER_MSVC 1
// # define MD_COMPILER_GCC 0
#elif defined( __GNUC__ )
# pragma message("Detected GCC")
// # define MD_COMPILER_CLANG 0
// # define MD_COMPILER_MSVC 0
# define MD_COMPILER_GCC 1
#elif defined( __clang__ )
# pragma message("Detected CLANG")
# define MD_COMPILER_CLANG 1
// # define MD_COMPILER_MSVC 0
// # define MD_COMPILER_GCC 0
#else
# error Unknown compiler
#endif
#if defined( __has_attribute )
# define MD_HAS_ATTRIBUTE( attribute ) __has_attribute( attribute )
#else
# define MD_HAS_ATTRIBUTE( attribute ) ( 0 )
#endif
#if defined(MD_GCC_VERSION_CHECK)
# undef MD_GCC_VERSION_CHECK
#endif
#if defined(GEN_GCC_VERSION)
# define MD_GCC_VERSION_CHECK(major,minor,patch) (GEN_GCC_VERSION >= GEN_VERSION_ENCODE(major, minor, patch))
#else
# define MD_GCC_VERSION_CHECK(major,minor,patch) (0)
#endif
#if ! defined(MD_COMPILER_C)
# ifdef __cplusplus
# define MD_COMPILER_C 0
# define MD_COMPILER_CPP 1
# else
# if defined(__STDC__)
# define MD_COMPILER_C 1
# define MD_COMPILER_CPP 0
# else
// Fallback for very old C compilers
# define MD_COMPILER_C 1
# define MD_COMPILER_CPP 0
# endif
# endif
#endif
#if MD_COMPILER_C
#pragma message("MD: Detected C")
#endif
#if MD_COMPILER_CPP
#pragma message("MD: Detected CPP")
#endif
#pragma endregion Platform Compiler
+21
View File
@@ -0,0 +1,21 @@
#if MD_INTELLISENSE_DIRECTIVES
#include "arch.h"
#include "os.h"
#include "compiler.h"
#endif
#pragma region Mandatory Includes
# include <stdarg.h>
# include <stddef.h>
# if defined( MD_SYSTEM_WINDOWS )
# include <intrin.h>
# endif
#if MD_COMPILER_C
#include <assert.h>
#include <stdbool.h>
#endif
#pragma endregion Mandatory Includes
+49
View File
@@ -0,0 +1,49 @@
#if MD_INTELLISENSE_DIRECTIVES
#include "cstd.h"
#endif
#ifndef MD_API
#if MD_COMPILER_MSVC
# ifdef MD_DYN_LINK
# ifdef MD_DYN_EXPORT
# define MD_API __declspec(dllexport)
# else
# define MD_API __declspec(dllimport)
# endif
# else
# define MD_API // Empty for static builds
# endif
#else
# ifdef MD_DYN_LINK
# define MD_API __attribute__((visibility("default")))
# else
# define MD_API // Empty for static builds
# endif
#endif
#endif // GEN_API
#ifndef internal
#define internal static
#endif
#ifndef local_persist
#define local_persist static
#endif
#if MD_DONT_USE_NAMESPACE || MD_COMPILER_C
# if MD_COMPILER_C
# define MD_NS
# define MD_NS_BEGIN
# define MD_NS_END
# else
# define MD_NS ::
# define MD_NS_BEGIN
# define MD_NS_END
# endif
#else
namespace MD {}
namespace md = MD;
# define MD_NS MD::
# define MD_NS_BEGIN namespace MD {
# define MD_NS_END }
#endif
+56
View File
@@ -0,0 +1,56 @@
#if MD_INTELLISENSE_DIRECTIVES
#pragma once
#endif
#pragma region Platform OS
#if defined( _WIN32 ) || defined( _WIN64 )
# ifndef MD_OS_WINDOWS
# define MD_OS_WINDOWS 1
# endif
#elif defined( __APPLE__ ) && defined( __MACH__ )
# ifndef MD_OS_OSX
# define MD_OS_OSX 1
# endif
# ifndef MD_OS_MACOS
# define MD_OS_MACOS 1
# endif
#elif defined( __unix__ )
# ifndef MD_OS_UNIX
# define MD_OS_UNIX 1
# endif
# if defined( ANDROID ) || defined( __ANDROID__ )
# ifndef MD_OS_ANDROID
# define MD_OS_ANDROID 1
# endif
# ifndef MD_OS_LINUX
# define MD_OS_LINUX 1
# endif
# elif defined( __linux__ )
# ifndef MD_OS_LINUX
# define MD_OS_LINUX 1
# endif
# elif defined( __FreeBSD__ ) || defined( __FreeBSD_kernel__ )
# ifndef MD_OS_FREEBSD
# define MD_OS_FREEBSD 1
# endif
# elif defined( __OpenBSD__ )
# ifndef MD_OS_OPENBSD
# define MD_OS_OPENBSD 1
# endif
# elif defined( __EMSCRIPTEN__ )
# ifndef MD_OS_EMSCRIPTEN
# define MD_OS_EMSCRIPTEN 1
# endif
# elif defined( __CYGWIN__ )
# ifndef MD_OS_CYGWIN
# define MD_OS_CYGWIN 1
# endif
# else
# error This UNIX operating system is not supported
# endif
#else
# error This operating system is not supported
#endif
#pragma endregion Platform OS
+11
View File
@@ -0,0 +1,11 @@
#if MD_INTELLISENSE_DIRECTIVES
#include "base_types.h"
#endif
typedef struct String8 String8;
struct String8
{
U8 *str;
U64 size;
};