diff --git a/.vscode/settings.json b/.vscode/settings.json index 193a956..8613d25 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,6 +14,8 @@ "xtr1common": "cpp", "cstddef": "cpp", "xmemory": "cpp", - "memory.h": "c" + "memory.h": "c", + "charconv": "c", + "xstring": "c" } } \ No newline at end of file diff --git a/code/base/command_line.c b/code/base/command_line.c index a5b33fd..fc97857 100644 --- a/code/base/command_line.c +++ b/code/base/command_line.c @@ -1,5 +1,4 @@ #ifdef MD_INTELLISENSE_DIRECTIVES -# pragma once # include "command_line.h" #endif diff --git a/code/base/entry_point.c b/code/base/entry_point.c index b024554..c4e035e 100644 --- a/code/base/entry_point.c +++ b/code/base/entry_point.c @@ -1,3 +1,9 @@ +#ifdef MD_INTELLISENSE_DIRECTIVES +# include "entry_point.h" +# include "arena.h" +# include "thread_context.h" +#endif + // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) @@ -11,7 +17,7 @@ main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **argum tmInitialize(sizeof(tm_data), (char *)tm_data); #endif ThreadNameF("[main thread]"); - Temp scratch = scratch_begin(0, 0); + TempArena scratch = scratch_begin(0, 0); String8List command_line_argument_strings = os_string_list_from_argcv(scratch.arena, (int)arguments_count, arguments); CmdLine cmdline = cmd_line_from_string_list(scratch.arena, command_line_argument_strings); B32 capture = cmd_line_has_flag(&cmdline, str8_lit("capture")); diff --git a/code/base/linkage.h b/code/base/linkage.h index 1b7e92c..4b96633 100644 --- a/code/base/linkage.h +++ b/code/base/linkage.h @@ -23,6 +23,18 @@ #endif #endif // GEN_API +#ifndef MD_API_C_BEGIN +# if MD_LANG_C +# define MD_API_C_BEGIN +# define MD_API_C_END +# define MD_API_C +# else +# define MD_API_C_BEGIN extern "C" { +# define MD_API_C_END } +# define MD_API_C_END extern "C" +# endif +#endif + #ifndef global // Global variables # ifdef MD_DYN_EXPORT # define global diff --git a/code/base/logger.h b/code/base/logger.h index 52a297d..9180dc0 100644 --- a/code/base/logger.h +++ b/code/base/logger.h @@ -1,3 +1,10 @@ +#ifdef MD_INTELLISENSE_DIRECTIVES +# pragma once +# include "base_types.h" +# include "strings.h" +# include "arena.h" +#endif + // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) diff --git a/code/base/macros.h b/code/base/macros.h index 28e75e2..83d07ca 100644 --- a/code/base/macros.h +++ b/code/base/macros.h @@ -29,7 +29,7 @@ //////////////////////////////// //~ erg: type casting -#if MD_COMPILER_CPP +#if MD_LANG_CPP # ifndef ccast # define ccast( type, value ) ( const_cast< type >( (value) ) ) # endif @@ -57,8 +57,8 @@ # endif #endif -#if ! defined(typeof) && ( ! MD_COMPILER_C || __STDC_VERSION__ < 202311L) -# if ! MD_COMPILER_C +#if ! defined(typeof) && ( ! MD_LANG_C || __STDC_VERSION__ < 202311L) +# if ! MD_LANG_C # define typeof decltype # elif defined(_MSC_VER) # define typeof __typeof__ @@ -69,17 +69,7 @@ # endif #endif -#ifndef MD_API_C_BEGIN -# if MD_COMPILER_C -# define MD_API_C_BEGIN -# define MD_API_C_END -# else -# define MD_API_C_BEGIN extern "C" { -# define MD_API_C_END } -# endif -#endif - -#if MD_COMPILER_C +#if MD_LANG_C # if __STDC_VERSION__ >= 202311L # define enum_underlying(type) : type # else @@ -89,7 +79,7 @@ # define enum_underlying(type) : type #endif -#if MD_COMPILER_C +#if MD_LANG_C # ifndef nullptr # define nullptr NULL # endif @@ -99,16 +89,16 @@ # endif #endif -#if ! defined(MD_PARAM_DEFAULT) && MD_COMPILER_CPP +#if ! defined(MD_PARAM_DEFAULT) && MD_LANG_CPP # define MD_PARAM_DEFAULT = {} #else # define MD_PARAM_DEFAULT #endif -#if MD_COMPILER_C +#if MD_LANG_C # ifndef static_assert # undef static_assert -# if MD_COMPILER_C && __STDC_VERSION__ >= 201112L +# if __STDC_VERSION__ >= 201112L # define static_assert(condition, message) _Static_assert(condition, message) # else # define static_assert(condition, message) typedef char static_assertion_##__LINE__[(condition)?1:-1] diff --git a/code/base/markup.c b/code/base/markup.c index 033fb49..c83195c 100644 --- a/code/base/markup.c +++ b/code/base/markup.c @@ -1,3 +1,7 @@ +#ifdef MD_INTELLISENSE_DIRECTIVES +# include "markup.h" +#endif + // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) diff --git a/code/base/memory.h b/code/base/memory.h index e97b0ea..14b8243 100644 --- a/code/base/memory.h +++ b/code/base/memory.h @@ -267,15 +267,16 @@ # define NO_ASAN #endif -#if ASAN_ENABLED -#pragma comment(lib, "clang_rt.asan-x86_64.lib") -MD_C_API void __asan_poison_memory_region(void const volatile *addr, size_t size); -MD_C_API void __asan_unpoison_memory_region(void const volatile *addr, size_t size); -# define AsanPoisonMemoryRegion(addr, size) __asan_poison_memory_region((addr), (size)) -# define AsanUnpoisonMemoryRegion(addr, size) __asan_unpoison_memory_region((addr), (size)) +#if MD_ASAN_ENABLED +# pragma comment(lib, "clang_rt.asan-x86_64.lib") + MD_C_API void __asan_poison_memory_region(void const volatile *addr, size_t size); + MD_C_API void __asan_unpoison_memory_region(void const volatile *addr, size_t size); + +# define AsanPoisonMemoryRegion(addr, size) __asan_poison_memory_region((addr), (size)) +# define AsanUnpoisonMemoryRegion(addr, size) __asan_unpoison_memory_region((addr), (size)) #else -# define AsanPoisonMemoryRegion(addr, size) ((void)(addr), (void)(size)) -# define AsanUnpoisonMemoryRegion(addr, size) ((void)(addr), (void)(size)) +# define AsanPoisonMemoryRegion(addr, size) ((void)(addr), (void)(size)) +# define AsanUnpoisonMemoryRegion(addr, size) ((void)(addr), (void)(size)) #endif //////////////////////////////// diff --git a/code/base/memory_substrate.h b/code/base/memory_substrate.h index ab364ff..4ba676c 100644 --- a/code/base/memory_substrate.h +++ b/code/base/memory_substrate.h @@ -21,15 +21,6 @@ #define MD__HIGHS ( MD__ONES * ( MD_U8_MAX / 2 + 1 ) ) #define MD__HAS_ZERO( x ) ( ( ( x ) - MD__ONES ) & ~( x ) & MD__HIGHS ) -#define swap(a, b) \ -do \ -{ \ - typeof(a) tmp = a; \ - a = b; \ - b = tmp; \ -} \ -while (0) - #if MD_COMPILER_MSVC || (MD_COMPILER_CLANG && MD_OS_WINDOWS) # pragma section(".rdata$", read) # define read_only __declspec(allocate(".rdata$")) @@ -44,13 +35,14 @@ while (0) # define read_only #endif -enum AllocType : u8 +enum AllocType enum_underlying(U32) { EAllocType_ALLOC, EAllocType_FREE, EAllocType_FREE_ALL, EAllocType_RESIZE, }; +typedef U32 AllocType; typedef void*(AllocatorProc)( void* allocator_data, AllocType type, SSIZE size, SSIZE alignment, void* old_memory, SSIZE old_size, U64 flags ); @@ -114,7 +106,7 @@ void* default_resize_align( AllocatorInfo a, void* ptr, SSIZE old_size, SSIZE ne MD_API void* heap_allocator_proc( void* allocator_data, AllocType type, SSIZE size, SSIZE alignment, void* old_memory, SSIZE old_size, U64 flags ); //! The heap allocator backed by operating system's memory manager. -constexpr AllocatorInfo heap( void ) { AllocatorInfo allocator = { heap_allocator_proc, nullptr }; return allocator; } +#define heap() (AllocatorInfo){ AllocatorInfo allocator = { heap_allocator_proc, nullptr }; return allocator; } //! Helper to allocate memory using heap allocator. #define malloc( sz ) alloc( heap(), sz ) diff --git a/code/base/space.h b/code/base/space.h new file mode 100644 index 0000000..e178a10 --- /dev/null +++ b/code/base/space.h @@ -0,0 +1,62 @@ +#ifdef MD_INTELLISENSE_DIRECTIVES +# pragma once +# include "math.h" +#endif + +//////////////////////////////// +//~ rjf: Basic Types & Spaces + +typedef enum Dimension +{ + Dimension_X, + Dimension_Y, + Dimension_Z, + Dimension_W, +} +Dimension; + +typedef enum Side +{ + Side_Invalid = -1, + Side_Min, + Side_Max, + Side_COUNT, +} +Side; +#define side_flip(s) ((Side)(!(s))) + +typedef enum Axis2 +{ + Axis2_Invalid = -1, + Axis2_X, + Axis2_Y, + Axis2_COUNT, +} +Axis2; +#define axis2_flip(a) ((Axis2)(!(a))) + +typedef enum Corner +{ + Corner_Invalid = -1, + Corner_00, + Corner_01, + Corner_10, + Corner_11, + Corner_COUNT +} +Corner; + +typedef enum Dir2 +{ + Dir2_Invalid = -1, + Dir2_Left, + Dir2_Up, + Dir2_Right, + Dir2_Down, + Dir2_COUNT +} +Dir2; + +#define axis2_from_dir2(d) (((d) & 1) ? Axis2_Y : Axis2_X) +#define side_from_dir2(d) (((d) < Dir2_Right) ? Side_Min : Side_Max) + diff --git a/code/base/strings.h b/code/base/strings.h index 8c0d491..6eb785e 100644 --- a/code/base/strings.h +++ b/code/base/strings.h @@ -5,7 +5,11 @@ # include "platform.h" # include "macros.h" # include "base_types.h" +# include "constants.h" +# include "math.h" +# include "thread_context.h" # include "memory.h" +# include "arena.h" #endif // Copyright (c) 2024 Epic Games Tools @@ -115,16 +119,6 @@ struct StringJoin String8 post; }; -//////////////////////////////// -//~ rjf: String Pair Types - -typedef struct String8TxtPtPair String8TxtPtPair; -struct String8TxtPtPair -{ - String8 string; - TxtPt pt; -}; - //////////////////////////////// //~ rjf: UTF Decoding Types @@ -298,8 +292,6 @@ internal String8List str8_split_path (Arena *arena, String8 internal void str8_path_list_resolve_dots_in_place(String8List *path, PathStyle style); internal String8 str8_path_list_join_by_style (Arena *arena, String8List *path, PathStyle style); -internal String8TxtPtPair str8_txt_pt_pair_from_string(String8 string); - //////////////////////////////// //~ rjf: UTF-8 & UTF-16 Decoding/Encoding @@ -339,10 +331,7 @@ internal String8 string_from_elapsed_time (Arena* arena, DateTime dt); internal String8 indented_from_string(Arena *arena, String8 string); -//////////////////////////////// -//~ rjf: Text Wrapping -internal String8List wrapped_lines_from_string(Arena *arena, String8 string, U64 first_line_max_width, U64 max_width, U64 wrap_indent); //////////////////////////////// //~ rjf: String <-> Color diff --git a/code/base/text.h b/code/base/text.h index 843f6ee..5b20d48 100644 --- a/code/base/text.h +++ b/code/base/text.h @@ -1,4 +1,43 @@ #ifdef MD_INTELLISENSE_DIRECTIVES -#pragma once - +# pragma once +# include "linkage.h" +# include "strings.h" +# include "arena.h" #endif + +//////////////////////////////// +//~ rjf: Text 2D Coordinates & Ranges + +typedef struct TxtPt TxtPt; +struct TxtPt +{ + S64 line; + S64 column; +}; + +typedef struct TxtRng TxtRng; +struct TxtRng +{ + TxtPt min; + TxtPt max; +}; + +//////////////////////////////// +//~ rjf: String Pair Types + +typedef struct String8TxtPtPair String8TxtPtPair; +struct String8TxtPtPair +{ + String8 string; + TxtPt pt; +}; + +//////////////////////////////// +//~ rjf: Text Path Helpers + +internal String8TxtPtPair str8_txt_pt_pair_from_string(String8 string); + +//////////////////////////////// +//~ rjf: Text Wrapping + +internal String8List wrapped_lines_from_string(Arena *arena, String8 string, U64 first_line_max_width, U64 max_width, U64 wrap_indent); diff --git a/code/base/thread_context.h b/code/base/thread_context.h index 4597e28..f26c172 100644 --- a/code/base/thread_context.h +++ b/code/base/thread_context.h @@ -1,41 +1,44 @@ +#ifdef MD_INTELLISENSE_DIRECTIVES +# pragma once +# include "linkage.h" +# include "base_types.h" +# include "strings.h" +# include "arena.h" +#endif + // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) -#ifndef BASE_THREAD_CONTEXT_H -#define BASE_THREAD_CONTEXT_H - //////////////////////////////// // NOTE(allen): Thread Context typedef struct TCTX TCTX; struct TCTX { - Arena *arenas[2]; + Arena* arenas[2]; - U8 thread_name[32]; + U8 thread_name[32]; U64 thread_name_size; - char *file_name; - U64 line_number; + char* file_name; + U64 line_number; }; //////////////////////////////// // NOTE(allen): Thread Context Functions -internal void tctx_init_and_equip(TCTX *tctx); -internal void tctx_release(void); -internal TCTX* tctx_get_equipped(void); +internal void tctx_init_and_equip(TCTX *tctx); +internal void tctx_release(void); +internal TCTX* tctx_get_equipped(void); -internal Arena* tctx_get_scratch(Arena **conflicts, U64 count); +internal Arena* tctx_get_scratch(Arena** conflicts, U64 count); -internal void tctx_set_thread_name(String8 name); -internal String8 tctx_get_thread_name(void); +internal void tctx_set_thread_name(String8 name); +internal String8 tctx_get_thread_name(void); -internal void tctx_write_srcloc(char *file_name, U64 line_number); -internal void tctx_read_srcloc(char **file_name, U64 *line_number); -#define tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__) +internal void tctx_write_srcloc(char* file_name, U64 line_number); +internal void tctx_read_srcloc (char** file_name, U64* line_number); +#define tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__) #define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count))) #define scratch_end(scratch) temp_end(scratch) - -#endif // BASE_THREAD_CONTEXT_H diff --git a/code/base/toolchain.h b/code/base/toolchain.h index e5ece6a..9364671 100644 --- a/code/base/toolchain.h +++ b/code/base/toolchain.h @@ -1,5 +1,5 @@ #ifdef MD_INTELLISENSE_DIRECTIVES -#pragma once +# pragma once #endif ////////////////////////////////