base progress

This commit is contained in:
ed
2025-02-01 23:43:46 -05:00
parent 078bf4b271
commit e19dd6b58c
14 changed files with 182 additions and 76 deletions
-1
View File
@@ -1,5 +1,4 @@
#ifdef MD_INTELLISENSE_DIRECTIVES
# pragma once
# include "command_line.h"
#endif
+7 -1
View File
@@ -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"));
+12
View File
@@ -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
+7
View File
@@ -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/)
+8 -18
View File
@@ -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]
+4
View File
@@ -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/)
+9 -8
View File
@@ -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
////////////////////////////////
+3 -11
View File
@@ -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 )
+62
View File
@@ -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)
+4 -15
View File
@@ -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
+41 -2
View File
@@ -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);
+21 -18
View File
@@ -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
+1 -1
View File
@@ -1,5 +1,5 @@
#ifdef MD_INTELLISENSE_DIRECTIVES
#pragma once
# pragma once
#endif
////////////////////////////////