From b028d7fa14884c11287058d054000ff4e6c4f770 Mon Sep 17 00:00:00 2001 From: Musa Mahmood Date: Tue, 25 Nov 2025 07:23:07 -0500 Subject: [PATCH] Move executable entry point outside of lib --- exe_main.cpp | 14 +-------- lib/Base/Array.h | 17 ---------- lib/Base/Base_Thread_Context.cpp | 23 ++++++++++---- lib/Base/Base_Thread_Context.h | 7 ++++- lib/OS/Base_Entry_Point.cpp | 54 -------------------------------- lib/OS/OS_Win32.cpp | 3 -- lib_main.cpp | 2 -- src/Base_Entry_Point.cpp | 44 ++++++++++++++++++++++++++ 8 files changed, 68 insertions(+), 96 deletions(-) delete mode 100644 lib/OS/Base_Entry_Point.cpp create mode 100644 src/Base_Entry_Point.cpp diff --git a/exe_main.cpp b/exe_main.cpp index edbac13..1818e25 100644 --- a/exe_main.cpp +++ b/exe_main.cpp @@ -1,15 +1,3 @@ #include "lib_main.cpp" +#include "src/Base_Entry_Point.cpp" -#if OS_WINDOWS - #if BUILD_CONSOLE_INTERFACE - int wmain(int argc, WCHAR **argv) { - Win32_Entry_Point(argc, argv); - return 0; - } - #else - int wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) { - Win32_Entry_Point(__argc, __wargv); - return 0; - } - #endif -#endif diff --git a/lib/Base/Array.h b/lib/Base/Array.h index 3182e21..fcd68c1 100644 --- a/lib/Base/Array.h +++ b/lib/Base/Array.h @@ -1,14 +1,7 @@ // Strongly influenced by Array.jai in Basic module. #pragma once -// #TODO: Array.h - // [x] Set allocations to use context.allocator interface - // For now, I'm just disabling alignment: - // [ ] Add back alignment, and make sure there's a way to pass alignment to NewArray, which gets passed to allocator.proc. - // [ ] Make versions of ArrayView initializer that takes allocator as a param - // [ ] Make version of array_free (ArrayView&) that takes allocator as a param // For Arena-Backed arrays use ArenaArray -// #define DEFAULT_ARRAY_ALIGNMENT 16 MSVC_RUNTIME_CHECKS_OFF @@ -19,7 +12,6 @@ struct Array { // downcasts to an ArrayView. T* data; s64 allocated; Allocator allocator; - // s64 alignment = DEFAULT_ARRAY_ALIGNMENT; Array() { memset(this, 0, sizeof(*this)); @@ -32,15 +24,6 @@ struct Array { // downcasts to an ArrayView. allocated = new_count; } - // initializer-list type instantiation: `Array new_array = {count, data}` - // (Musa) This array cannot then be resized. Why do I even have this? Do I need it? - // Array(s64 new_count, void* new_data) { - // count = new_count; - // data = (T*)new_data; - // allocator = { nullptr, nullptr }; // NOT RESIZABLE. - // allocated = new_count; - // } - // Used by array_zero, array_copy, etc. Array(s64 new_count, void* new_data, s64 _allocated) { count = new_count; diff --git a/lib/Base/Base_Thread_Context.cpp b/lib/Base/Base_Thread_Context.cpp index 52dbeeb..790f0d2 100644 --- a/lib/Base/Base_Thread_Context.cpp +++ b/lib/Base/Base_Thread_Context.cpp @@ -1,6 +1,22 @@ // See Context_Base in jai, and TCTX in raddebugger: -Thread_Context* get_thread_context(); +internal void Bootstrap_Main_Thread_Context () { + // 0. Setup general MB(70) allocator + GPAllocator_Initialize_Allocation_Tracker(); + // 1. Setup arena table + initialize_arena_table(); + // 2. Setup thread local context + ExpandableArena* arena_ex = expandable_arena_new(Arena_Reserve::Size_64M, 16); + + thread_local_context = New(get_allocator(arena_ex)); + thread_local_context->temp = expandable_arena_new(Arena_Reserve::Size_2M, 16); + thread_local_context->arena = arena_ex; + thread_local_context->allocator = get_allocator(arena_ex); + thread_local_context->thread_idx = 0; + thread_local_context->thread_name = "Main Thread"; + // thread_local_context->logger = init_logger(); + +} struct Push_Arena { Thread_Context* context; @@ -47,11 +63,6 @@ struct Push_Allocator { PROTOTYPING_API Allocator get_temp_allocator(); PROTOTYPING_API Allocator get_context_allocator(); - - -// C_LINKAGE thread_static TCTX* tctx_thread_local; -thread_static Thread_Context* thread_local_context; - // Start from w32_entry_point_caller -> // see main_thread_base_entry_point // //- rjf: set up thread context diff --git a/lib/Base/Base_Thread_Context.h b/lib/Base/Base_Thread_Context.h index df5d36e..2dd6a9f 100644 --- a/lib/Base/Base_Thread_Context.h +++ b/lib/Base/Base_Thread_Context.h @@ -17,4 +17,9 @@ struct Thread_Context { string thread_name; }; -Thread_Context* get_thread_context (); \ No newline at end of file +// C_LINKAGE thread_static TCTX* tctx_thread_local; +thread_static Thread_Context* thread_local_context; + +Thread_Context* get_thread_context (); + +internal void Bootstrap_Main_Thread_Context (); diff --git a/lib/OS/Base_Entry_Point.cpp b/lib/OS/Base_Entry_Point.cpp deleted file mode 100644 index f5c576d..0000000 --- a/lib/OS/Base_Entry_Point.cpp +++ /dev/null @@ -1,54 +0,0 @@ -internal void Bootstrap_Main_Thread_Context () { - // 0. Setup general MB(70) allocator - GPAllocator_Initialize_Allocation_Tracker(); - // 1. Setup arena table - initialize_arena_table(); - // 2. Setup thread local context - ExpandableArena* arena_ex = expandable_arena_new(Arena_Reserve::Size_64M, 16); - - thread_local_context = New(get_allocator(arena_ex)); - thread_local_context->temp = expandable_arena_new(Arena_Reserve::Size_2M, 16); - thread_local_context->arena = arena_ex; - thread_local_context->allocator = get_allocator(arena_ex); - thread_local_context->thread_idx = 0; - thread_local_context->thread_name = "Main Thread"; - // thread_local_context->logger = init_logger(); - -} - -// #include "lib/Base/Arena_Array.h" -void run_arena_array_tests () { - { push_arena(thread_local_context->temp); - push_alignment(thread_local_context->temp, 1); - auto_reset(thread_local_context->temp); - auto something = New(); - auto something2 = New>(); - auto something3 = internal_alloc(MB(70)); - } - - { push_allocator(GPAllocator()); - auto something = New(); - auto something2 = New>(); - } - - // { auto na = arena_array_new(64000, Arena_Reserve::Size_64G); - // array_add(...) - // } -} - -internal void Main_Entry_Point (int argc, WCHAR **argv) { - run_arena_array_tests(); - - // Worker_Info* info = (Worker_Info*)GPAllocator_New(sizeof(Worker_Info), 64); - temp_reset(); - debug_break(); - printf("sizeof(Array): %zd\n", sizeof(Array)); - printf("sizeof(Arena): %zd\n", sizeof(Arena)); - printf("sizeof(Worker_Info): %zd\n", sizeof(Thread)); - printf("sizeof(Worker_Info): %zd\n", sizeof(Worker_Info)); - - // #TODO: - // [ ] Launch second thread - // [ ] Setup Mouse and Keyboard Inputs - // OS_Create_Window(); -} diff --git a/lib/OS/OS_Win32.cpp b/lib/OS/OS_Win32.cpp index 4544e7f..6586f18 100644 --- a/lib/OS/OS_Win32.cpp +++ b/lib/OS/OS_Win32.cpp @@ -67,7 +67,6 @@ internal LONG WINAPI Win32_Exception_Filter (EXCEPTION_POINTERS* exception_ptrs) return 0; } -internal void Bootstrap_Main_Thread_Context (); // internal void Main_Entry_Point (int argc, WCHAR **argv); internal void Win32_Entry_Point (int argc, WCHAR **argv) { // See: w32_entry_point_caller(); (raddebugger) @@ -173,8 +172,6 @@ internal void Win32_Entry_Point (int argc, WCHAR **argv) { // [ ] GetEnvironmentStringsW // temp_reset(); printf("Hello there!\n\n"); - // See: main_thread_base_entry_point - Main_Entry_Point(argc, argv); } C_LINKAGE DWORD OS_Windows_Thread_Entry_Point (void* parameter) { diff --git a/lib_main.cpp b/lib_main.cpp index 9da8f47..d72e565 100644 --- a/lib_main.cpp +++ b/lib_main.cpp @@ -28,8 +28,6 @@ // OS-Abstraction Layer #include "lib/Base/Threads.cpp" -#include "lib/OS/Base_Entry_Point.cpp" - #if OS_WINDOWS # include "lib/OS/OS_Win32.cpp" diff --git a/src/Base_Entry_Point.cpp b/src/Base_Entry_Point.cpp new file mode 100644 index 0000000..f21b412 --- /dev/null +++ b/src/Base_Entry_Point.cpp @@ -0,0 +1,44 @@ +void run_arena_array_tests () { + { push_arena(thread_local_context->temp); + push_alignment(thread_local_context->temp, 1); + auto_reset(thread_local_context->temp); + auto something = New(); + auto something2 = New>(); + auto something3 = internal_alloc(MB(70)); + } + + { push_allocator(GPAllocator()); + auto something = New(); + auto something2 = New>(); + } + + // { auto na = arena_array_new(64000, Arena_Reserve::Size_64G); + // array_add(...) + // } +} + +internal void Main_Entry_Point (int argc, WCHAR **argv) { + temp_reset(); + // #TODO: + // [ ] Launch second thread + // [ ] Setup Mouse and Keyboard Inputs + // OS_Create_Window(); +} + +#if OS_WINDOWS + #if BUILD_CONSOLE_INTERFACE + int wmain(int argc, WCHAR **argv) { + Win32_Entry_Point(argc, argv); + // See: main_thread_base_entry_point + Main_Entry_Point(argc, argv); + return 0; + } + #else + int wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) { + Win32_Entry_Point(__argc, __wargv); + // See: main_thread_base_entry_point + Main_Entry_Point(__argc, __wargv); + return 0; + } + #endif +#endif