From cc530044c370391a89fea01dc170cb2dbb335e4f Mon Sep 17 00:00:00 2001 From: SoraKatadzuma Date: Sun, 5 Jul 2026 20:38:03 -0500 Subject: [PATCH] Initial commit --- .editorconfig | 9 ++ .gitignore | 3 + chinookfile | 18 ++++ include/malunal/types.h | 232 ++++++++++++++++++++++++++++++++++++++++ tests/assertions.c | 9 ++ 5 files changed, 271 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 chinookfile create mode 100644 include/malunal/types.h create mode 100644 tests/assertions.c diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c6c8b36 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2903287 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.chinook +.environ +.vscode diff --git a/chinookfile b/chinookfile new file mode 100644 index 0000000..d0f6f8c --- /dev/null +++ b/chinookfile @@ -0,0 +1,18 @@ +name: types +gpid: malunal +semv: 1.0.0 + +targets: +- name: malunal.types + type: interface + +tests: +- name: assertions + type: program + deps: + - malunal.types + srcs: + - ./tests/assertions.c + +exports: +- malunal.types diff --git a/include/malunal/types.h b/include/malunal/types.h new file mode 100644 index 0000000..4008c28 --- /dev/null +++ b/include/malunal/types.h @@ -0,0 +1,232 @@ +/** + * @file types.h + * @brief Contains the definitions of various types used within malunal code + * bases and libraries. + * @author John Christman (sorakatadzuma@gmail.com) + * @copyright Malunal Studios, LLC. + */ +#ifndef MALUNAL_TYPES_HEADER +#define MALUNAL_TYPES_HEADER + +#if __STDC_VERSION__ < 201112L +# error "This library requires C11 or later" +#endif + +#if defined(__SIZEOF_POINTER__) +# define MALUNAL_POINTER_SIZE __SIZEOF_POINTER__ +#elif defined(_MSC_VER) +# if defined(_M_X64) || defined(_M_ARM64) +# define MY_PTR_SIZE 8 +# elif defined(_M_IX86) || defined(_M_ARM) +# define MY_PTR_SIZE 4 +# else /* Unrecognized MSVC target */ +# error "Unrecognized MSVC target architecture" +# endif /* MSVC compiler check */ +#else /* Unrecognized compiler, no support */ +# error "Unrecognized compiler - add support explicitly" +#endif /* Compiler dependent pointer size check */ + + +/** + * @brief Our own definition of @c void. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +typedef void malunal_void_t; + +/** + * @brief Our own definition of a mutable pointer. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +typedef void* malunal_mptr_t; + +/** + * @brief Our own definition of an immutable pointer. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +typedef const void* malunal_iptr_t; + +/** + * @brief Our own definition of @c char. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +typedef char malunal_char_t; + +/** + * @brief Our own definition of a mutable string. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +typedef char malunal_str_t; + +/** + * @brief Our own definition of a constant string. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +typedef const char* malunal_cstr_t; + +/** + * @brief Our own definition of @c bool. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +typedef _Bool malunal_bool_t; + +/** + * @brief Our own definition of an 8-bit signed integer. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +typedef signed char malunal_int8_t; + +/** + * @brief Our own definition of an 16-bit signed integer. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +typedef signed short malunal_int16_t; + +/** + * @brief Our own definition of an 32-bit signed integer. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +typedef signed int malunal_int32_t; + +/** + * @brief Our own definition of an 8-bit unsigned integer. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +typedef unsigned char malunal_uint8_t; + +/** + * @brief Our own definition of an 16-bit unsigned integer. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +typedef unsigned short malunal_uint16_t; + +/** + * @brief Our own definition of an 32-bit unsigned integer. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +typedef unsigned int malunal_uint32_t; + + +/** + * @typedef malunal_int64_t + * @brief Our own definition of an 64-bit signed integer. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +/** + * @typedef malunal_uint64_t + * @brief Our own definition of an 64-bit unsigned integer. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +#if defined(_MSC_VER) +typedef signed __int64 malunal_int64_t; +typedef unsigned __int64 malunal_uint64_t; +#else +typedef signed long long malunal_int64_t; +typedef unsigned long long malunal_uint64_t; +#endif /* Compiler specific. */ + + +/** + * @typedef malunal_ptrdiff_t + * @brief Our own definition of an 64-bit pointer difference. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +/** + * @typedef malunal_intptr_t + * @brief Our own definition of an 64-bit signed integer pointer. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +/** + * @typedef malunal_size_t + * @brief Our own definition of an 64-bit unsigned integer. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +/** + * @typedef malunal_uintptr_t + * @brief Our own definition of an 64-bit unsigned integer pointer. + * @details This is provided, like all of the types in this header, to meet + * modern standards and to exist specifically to match how we name + * many of our other types. + */ +#if MALUNAL_POINTER_SIZE == 8 +typedef malunal_int64_t malunal_ptrdiff_t; +typedef malunal_int64_t malunal_intptr_t; +typedef malunal_uint64_t malunal_size_t; +typedef malunal_uint64_t malunal_uintptr_t; +#elif MALUNAL_POINTER_SIZE == 4 +typedef malunal_int32_t malunal_ptrdiff_t; +typedef malunal_int32_t malunal_intptr_t; +typedef malunal_uint32_t malunal_size_t; +typedef malunal_uint32_t malunal_uintptr_t; +#else +# error "Unsupported pointer size" +#endif + + +_Static_assert( + sizeof(malunal_int8_t) == 1, + "malunal_int8_t must be 1 byte" +); + +_Static_assert( + sizeof(malunal_int16_t) == 2, + "malunal_int16_t must be 2 bytes" +); + +_Static_assert( + sizeof(malunal_int32_t) == 4, + "malunal_int32_t must be 4 bytes" +); + +_Static_assert( + sizeof(malunal_int64_t) == 8, + "malunal_int64_t must be 8 bytes" +); + +_Static_assert( + sizeof(malunal_size_t) == sizeof(void*), + "malunal_size_t must match pointer width" +); + +_Static_assert( + sizeof(malunal_uintptr_t) == sizeof(void*), + "malunal_uintptr_t must match pointer width" +); + + +#endif /* MALUNAL_TYPES_HEADER */ diff --git a/tests/assertions.c b/tests/assertions.c new file mode 100644 index 0000000..4a2bb1c --- /dev/null +++ b/tests/assertions.c @@ -0,0 +1,9 @@ +#include "malunal/types.h" + +malunal_int32_t +main( + malunal_int32_t argc, + malunal_str_t* argv +) { + return 0; +}