From c47270702a1bd4485f911a4b5ca3500c021dc710 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 30 Sep 2019 19:06:21 -0700 Subject: [PATCH] Thread context now introduced to 4coder in ALL layers (booya!) :) --- 4coder_app_links_allocator.cpp | 54 ++++------ 4coder_base_commands.cpp | 27 ++--- 4coder_base_types.cpp | 130 +++++++++++++++++++++++-- 4coder_base_types.h | 32 +++++- 4coder_combined_write_commands.cpp | 4 +- 4coder_config.cpp | 5 +- 4coder_default_framework.cpp | 25 ++--- 4coder_default_framework_variables.cpp | 2 +- 4coder_default_hooks.cpp | 2 +- 4coder_experiments.cpp | 70 +++++++------ 4coder_generated/app_functions.h | 17 +--- 4coder_generated/command_metadata.h | 126 ++++++++++++------------ 4coder_insertion.cpp | 4 +- 4coder_jump_lister.cpp | 4 +- 4coder_jump_sticky.cpp | 13 +-- 4coder_lists.cpp | 41 +++----- 4coder_log_parser.cpp | 26 ++--- 4coder_project_commands.cpp | 27 ++--- 4coder_remapping_commands.cpp | 12 +-- 4coder_search.cpp | 18 ++-- 4coder_ui_helper.cpp | 36 +++---- 4coder_ui_helper.h | 2 +- 4ed.cpp | 69 ++++++------- 4ed.h | 18 +--- 4ed_allocator_models.cpp | 27 +++-- 4ed_api_implementation.cpp | 52 ++++------ 4ed_app_models.h | 8 +- 4ed_app_target.cpp | 6 -- 4ed_buffer.cpp | 6 +- 4ed_dynamic_variables.cpp | 3 +- 4ed_edit.cpp | 21 ++-- 4ed_file.cpp | 25 ++--- 4ed_history.cpp | 21 ++-- 4ed_history.h | 2 +- 4ed_text_layout.cpp | 17 ++-- 4ed_text_layout.h | 4 +- platform_all/4ed_shared_init_logic.cpp | 51 ++-------- platform_win32/win32_4ed.cpp | 53 +++++----- 38 files changed, 527 insertions(+), 533 deletions(-) diff --git a/4coder_app_links_allocator.cpp b/4coder_app_links_allocator.cpp index 4e7aabaa..1330ef7b 100644 --- a/4coder_app_links_allocator.cpp +++ b/4coder_app_links_allocator.cpp @@ -4,50 +4,38 @@ // TOP -internal void -scratch_block__init(Scratch_Block *block, Arena *arena){ - block->temp = begin_temp(arena); -} - -Scratch_Block::Scratch_Block(Temp_Memory t){ - this->temp = t; -} - -Scratch_Block::Scratch_Block(Arena *arena){ - scratch_block__init(this, arena); +Scratch_Block::Scratch_Block(Application_Links *app, Scratch_Share_Code share){ + scratch_block__init(this, get_thread_context(app), share); } Scratch_Block::Scratch_Block(Application_Links *app){ - scratch_block__init(this, context_get_arena(app)); -} - -Scratch_Block::~Scratch_Block(){ - end_temp(this->temp); -} - -Scratch_Block::operator Arena*(){ - return(this->temp.temp_memory_arena.arena); -} - -void Scratch_Block::restore(void){ - end_temp(this->temp); + scratch_block__init(this, get_thread_context(app), share_code_default); } //////////////////////////////// -internal Arena -make_arena_app_links(Application_Links *app, umem chunk_size, umem align){ - return(make_arena(context_get_base_allocator(app), chunk_size, align)); +internal Arena* +reserve_arena(Application_Links *app, umem chunk_size, umem align){ + Thread_Context *tctx = get_thread_context(app); + return(reserve_arena(tctx, chunk_size, align)); } -internal Arena -make_arena_app_links(Application_Links *app, umem chunk_size){ - return(make_arena_app_links(app, chunk_size, 8)); +internal Arena* +reserve_arena(Application_Links *app, umem chunk_size){ + Thread_Context *tctx = get_thread_context(app); + return(reserve_arena(tctx, chunk_size)); } -internal Arena -make_arena_app_links(Application_Links *app){ - return(make_arena_app_links(app, KB(16), 8)); +internal Arena* +reserve_arena(Application_Links *app){ + Thread_Context *tctx = get_thread_context(app); + return(reserve_arena(tctx)); +} + +internal void +release_arena(Application_Links *app, Arena *arena){ + Thread_Context *tctx = get_thread_context(app); + release_arena(tctx, arena); } // BOTTOM diff --git a/4coder_base_commands.cpp b/4coder_base_commands.cpp index 673939d0..a08a0999 100644 --- a/4coder_base_commands.cpp +++ b/4coder_base_commands.cpp @@ -1232,7 +1232,7 @@ CUSTOM_DOC("Queries the user for a string, and incrementally replace every occur static void save_all_dirty_buffers_with_postfix(Application_Links *app, String_Const_u8 postfix){ - Arena *scratch = context_get_arena(app); + Scratch_Block scratch(app); for (Buffer_ID buffer = get_buffer_next(app, 0, AccessOpen); buffer != 0; buffer = get_buffer_next(app, buffer, AccessOpen)){ @@ -1317,8 +1317,7 @@ CUSTOM_DOC("Queries the user for a file name and saves the contents of the curre View_ID view = get_active_view(app, AccessAll); Buffer_ID buffer = view_get_buffer(app, view, AccessAll); - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app); String_Const_u8 buffer_name = push_buffer_unique_name(app, scratch, buffer); // Query the user @@ -1342,8 +1341,6 @@ CUSTOM_DOC("Queries the user for a file name and saves the contents of the curre } } } - - end_temp(temp); } CUSTOM_COMMAND_SIG(rename_file_query) @@ -1352,8 +1349,7 @@ CUSTOM_DOC("Queries the user for a new name and renames the file of the current View_ID view = get_active_view(app, AccessAll); Buffer_ID buffer = view_get_buffer(app, view, AccessAll); - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app); String_Const_u8 file_name = push_buffer_file_name(app, scratch, buffer); if (file_name.size > 0){ @@ -1382,8 +1378,6 @@ CUSTOM_DOC("Queries the user for a new name and renames the file of the current } } - - end_temp(temp); } CUSTOM_COMMAND_SIG(make_directory_query) @@ -1616,11 +1610,9 @@ CUSTOM_DOC("Saves the current buffer.") { View_ID view = get_active_view(app, AccessProtected); Buffer_ID buffer = view_get_buffer(app, view, AccessProtected); - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app); String_Const_u8 file_name = push_buffer_file_name(app, scratch, buffer); buffer_save(app, buffer, file_name, 0); - end_temp(temp); } CUSTOM_COMMAND_SIG(reopen) @@ -1711,7 +1703,7 @@ CUSTOM_DOC("Advances forwards through the undo history of the current buffer.") CUSTOM_COMMAND_SIG(undo_all_buffers) CUSTOM_DOC("Advances backward through the undo history in the buffer containing the most recent regular edit.") { - Arena *scratch = context_get_arena(app); + Scratch_Block scratch(app, Scratch_Share); i32 highest_edit_number = -1; Buffer_ID first_buffer_match = 0; Buffer_ID last_buffer_match = 0; @@ -1738,7 +1730,6 @@ CUSTOM_DOC("Advances backward through the undo history in the buffer containing } } - Temp_Memory temp = begin_temp(scratch); Buffer_ID *match_buffers = push_array(scratch, Buffer_ID, match_count); i32 *new_positions = push_array(scratch, i32, match_count); match_count = 0; @@ -1778,14 +1769,13 @@ CUSTOM_DOC("Advances backward through the undo history in the buffer containing } view_buffer_set(app, match_buffers, new_positions, match_count); - - end_temp(temp); } CUSTOM_COMMAND_SIG(redo_all_buffers) CUSTOM_DOC("Advances forward through the undo history in the buffer containing the most recent regular edit.") { - Arena *scratch = context_get_arena(app); + Scratch_Block scratch(app, Scratch_Share); + i32 lowest_edit_number = 0x7FFFFFFF; Buffer_ID first_buffer_match = 0; Buffer_ID last_buffer_match = 0; @@ -1813,7 +1803,6 @@ CUSTOM_DOC("Advances forward through the undo history in the buffer containing t } } - Temp_Memory temp = begin_temp(scratch); Buffer_ID *match_buffers = push_array(scratch, Buffer_ID, match_count); i32 *new_positions = push_array(scratch, i32, match_count); match_count = 0; @@ -1854,8 +1843,6 @@ CUSTOM_DOC("Advances forward through the undo history in the buffer containing t } view_buffer_set(app, match_buffers, new_positions, match_count); - - end_temp(temp); } //////////////////////////////// diff --git a/4coder_base_types.cpp b/4coder_base_types.cpp index 7f714dce..2d9ea78d 100644 --- a/4coder_base_types.cpp +++ b/4coder_base_types.cpp @@ -2416,7 +2416,7 @@ make_arena(Base_Allocator *allocator, umem chunk_size){ } internal Arena make_arena(Base_Allocator *allocator){ - return(make_arena(allocator, KB(16), 8)); + return(make_arena(allocator, KB(64), 8)); } internal Cursor_Node* arena__new_node(Arena *arena, umem min_size){ @@ -2575,6 +2575,120 @@ end_temp(Temp_Memory temp){ //////////////////////////////// +internal void +thread_ctx_init(Thread_Context *tctx, Base_Allocator *allocator){ + block_zero_struct(tctx); + tctx->allocator = allocator; + tctx->node_arena = make_arena(allocator, KB(4), 8); +} + +internal Arena* +reserve_arena(Thread_Context *tctx, umem chunk_size, umem align){ + Arena_Node *node = tctx->free_arenas; + if (node != 0){ + sll_stack_pop(tctx->free_arenas); + } + else{ + node = push_array_zero(&tctx->node_arena, Arena_Node, 1); + } + node->arena = make_arena(tctx->allocator, chunk_size, align); + return(&node->arena); +} + +internal Arena* +reserve_arena(Thread_Context *tctx, umem chunk_size){ + return(reserve_arena(tctx, chunk_size, 8)); +} + +internal Arena* +reserve_arena(Thread_Context *tctx){ + return(reserve_arena(tctx, KB(64), 8)); +} + +internal void +release_arena(Thread_Context *tctx, Arena *arena){ + Arena_Node *node = CastFromMember(Arena_Node, arena, arena); + linalloc_clear(arena); + sll_stack_push(tctx->free_arenas, node); +} + +//////////////////////////////// + +internal void +scratch_block__init(Scratch_Block *block, Arena *arena){ + block->arena = arena; + block->temp = begin_temp(arena); + block->do_full_clear = false; +} + +internal void +scratch_block__init(Scratch_Block *block, Thread_Context *tctx, Scratch_Share_Code share){ + block->tctx = tctx; + Arena *arena = tctx->sharable_scratch; + if (arena != 0){ + block->temp = begin_temp(arena); + block->do_full_clear = false; + } + else{ + arena = reserve_arena(tctx); + block->do_full_clear = true; + } + block->arena = arena; + block->sharable_restore = tctx->sharable_scratch; + if (share == Scratch_Share){ + tctx->sharable_scratch = arena; + } + else{ + tctx->sharable_scratch = 0; + } +} + +Scratch_Block::Scratch_Block(Temp_Memory t){ + this->temp = t; +} + +Scratch_Block::Scratch_Block(Arena *arena){ + scratch_block__init(this, arena); +} + +global_const Scratch_Share_Code share_code_default = Scratch_DontShare; + +Scratch_Block::Scratch_Block(Thread_Context *tctx, Scratch_Share_Code share){ + scratch_block__init(this, tctx, share); +} + +Scratch_Block::Scratch_Block(Thread_Context *tctx){ + scratch_block__init(this, tctx, share_code_default); +} + +Scratch_Block::~Scratch_Block(){ + if (this->do_full_clear){ + Assert(this->tctx != 0); + release_arena(this->tctx, this->arena); + } + else{ + end_temp(this->temp); + } + if (this->tctx != 0){ + this->tctx->sharable_scratch = this->sharable_restore; + } +} + +Scratch_Block::operator Arena*(){ + return(this->arena); +} + +void Scratch_Block::restore(void){ + if (this->do_full_clear){ + linalloc_clear(this->arena); + } + else{ + end_temp(this->temp); + } +} + +//////////////////////////////// + #define heap__sent_init(s) (s)->next=(s)->prev=(s) #define heap__insert_next(p,n) ((n)->next=(p)->next,(n)->prev=(p),(n)->next->prev=(n),(p)->next=(n)) #define heap__insert_prev(p,n) ((n)->prev=(p)->prev,(n)->next=(p),(n)->prev->next=(n),(p)->prev=(n)) @@ -2611,7 +2725,8 @@ heap_assert_good(Heap *heap){ internal void heap_init(Heap *heap, Base_Allocator *allocator){ - heap->arena = make_arena(allocator, KB(64), KB(8)); + heap->arena_ = make_arena(allocator); + heap->arena = &heap->arena_; heap__sent_init(&heap->in_order); heap__sent_init(&heap->free_nodes); heap->used_space = 0; @@ -2619,11 +2734,14 @@ heap_init(Heap *heap, Base_Allocator *allocator){ } internal Base_Allocator* +heap_get_base_allocator(Heap *heap){ + return(heap->arena->base_allocator); +} + +internal void heap_free_all(Heap *heap){ - Base_Allocator *allocator = heap->arena.base_allocator; - linalloc_clear(&heap->arena); + linalloc_clear(heap->arena); block_zero_struct(heap); - return(allocator); } internal void @@ -2641,7 +2759,7 @@ heap__extend(Heap *heap, void *memory, umem size){ internal void heap__extend_automatic(Heap *heap, umem size){ - void *memory = push_array(&heap->arena, u8, size); + void *memory = push_array(heap->arena, u8, size); heap__extend(heap, memory, size); } diff --git a/4coder_base_types.h b/4coder_base_types.h index 8044c27f..384585f4 100644 --- a/4coder_base_types.h +++ b/4coder_base_types.h @@ -1097,14 +1097,41 @@ struct Temp_Memory{ }; }; +//////////////////////////////// + +union Arena_Node{ + Arena_Node *next; + Arena arena; +}; +struct Thread_Context{ + Base_Allocator *allocator; + Arena node_arena; + Arena_Node *free_arenas; + Arena *sharable_scratch; +}; + +typedef i32 Scratch_Share_Code; +enum{ + Scratch_DontShare, + Scratch_Share, +}; + struct Scratch_Block{ + Arena *arena; + Temp_Memory temp; + b32 do_full_clear; + Thread_Context *tctx; + Arena *sharable_restore; + Scratch_Block(Temp_Memory temp); Scratch_Block(Arena *arena); + Scratch_Block(struct Thread_Context *tctx, Scratch_Share_Code share); + Scratch_Block(struct Thread_Context *tctx); + Scratch_Block(struct Application_Links *app, Scratch_Share_Code share); Scratch_Block(struct Application_Links *app); ~Scratch_Block(); operator Arena*(); void restore(void); - Temp_Memory temp; }; //////////////////////////////// @@ -1126,7 +1153,8 @@ struct Heap_Node{ }; struct Heap{ - Arena arena; + Arena arena_; + Arena *arena; Heap_Basic_Node in_order; Heap_Basic_Node free_nodes; umem used_space; diff --git a/4coder_combined_write_commands.cpp b/4coder_combined_write_commands.cpp index 4fce0ee3..4aca4931 100644 --- a/4coder_combined_write_commands.cpp +++ b/4coder_combined_write_commands.cpp @@ -219,8 +219,7 @@ snippet_lister__parameterized(Application_Links *app, Snippet_Array snippet_arra View_ID view = get_active_view(app, AccessAll); view_end_ui_mode(app, view); - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app, Scratch_Share); i32 option_count = snippet_array.count; Lister_Option *options = push_array(scratch, Lister_Option, option_count); for (i32 i = 0; i < snippet_array.count; i += 1){ @@ -229,7 +228,6 @@ snippet_lister__parameterized(Application_Links *app, Snippet_Array snippet_arra options[i].user_data = IntAsPtr(i); } begin_integrated_lister__basic_list(app, "Snippet:", activate_snippet, &snippet_array, sizeof(snippet_array), options, option_count, 0, view); - end_temp(temp); } CUSTOM_COMMAND_SIG(snippet_lister) diff --git a/4coder_config.cpp b/4coder_config.cpp index 607a2b40..a7b5197f 100644 --- a/4coder_config.cpp +++ b/4coder_config.cpp @@ -1437,8 +1437,7 @@ config_feedback_int(Arena *arena, List_String_Const_u8 *list, char *name, i32 va static void load_config_and_apply(Application_Links *app, Arena *out_arena, Config_Data *config, i32 override_font_size, b32 override_hinting){ - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app); linalloc_clear(out_arena); Config *parsed = config_parse__file_name(app, out_arena, "config.4coder", config); @@ -1534,8 +1533,6 @@ load_config_and_apply(Application_Links *app, Arena *out_arena, Config_Data *con modify_global_face_by_description(app, description); } } - - end_temp(temp); } #if 0 diff --git a/4coder_default_framework.cpp b/4coder_default_framework.cpp index 36c95a63..0aed35d3 100644 --- a/4coder_default_framework.cpp +++ b/4coder_default_framework.cpp @@ -29,11 +29,9 @@ lock_jump_buffer(Application_Links *app, char *name, i32 size){ static void lock_jump_buffer(Application_Links *app, Buffer_ID buffer_id){ - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app); String_Const_u8 buffer_name = push_buffer_unique_name(app, scratch, buffer_id); lock_jump_buffer(app, buffer_name); - end_temp(temp); } static View_ID @@ -147,8 +145,7 @@ get_next_view_after_active(Application_Links *app, Access_Flag access){ static void view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 count){ if (count > 0){ - Arena *arena = context_get_arena(app); - Temp_Memory temp = begin_temp(arena); + Scratch_Block scratch(app, Scratch_Share); struct View_Node{ View_Node *next; @@ -167,7 +164,7 @@ view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 View_Node *primary_view_last = 0; i32 available_view_count = 0; - primary_view_first = primary_view_last = push_array(arena, View_Node, 1); + primary_view_first = primary_view_last = push_array(scratch, View_Node, 1); primary_view_last->next = 0; primary_view_last->view_id = view_id; available_view_count += 1; @@ -176,7 +173,7 @@ view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 if (view_id == first_view_id){ break; } - View_Node *node = push_array(arena, View_Node, 1); + View_Node *node = push_array(scratch, View_Node, 1); primary_view_last->next = node; node->next = 0; node->view_id = view_id; @@ -191,8 +188,6 @@ view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 view_set_cursor_and_preferred_x(app, node->view_id, seek_pos(positions[i])); } } - - end_temp(temp); } } @@ -363,8 +358,8 @@ CUSTOM_DOC("Switch to a named key binding map.") static void default_4coder_initialize(Application_Links *app, char **command_line_files, i32 file_count, i32 override_font_size, b32 override_hinting){ - Base_Allocator *allocator = context_get_base_allocator(app); - heap_init(&global_heap, allocator); + Thread_Context *tctx = get_thread_context(app); + heap_init(&global_heap, tctx->allocator); #define M \ "Welcome to " VERSION "\n" \ @@ -379,8 +374,8 @@ default_4coder_initialize(Application_Links *app, char **command_line_files, i32 #if 0 load_folder_of_themes_into_live_set(app, &global_part, "themes"); #endif - global_config_arena = make_arena_app_links(app); - load_config_and_apply(app, &global_config_arena, &global_config, override_font_size, override_hinting); + global_config_arena = reserve_arena(app); + load_config_and_apply(app, global_config_arena, &global_config, override_font_size, override_hinting); view_rewrite_loc = managed_id_declare(app, SCu8("DEFAULT.rewrite" )); view_next_rewrite_loc = managed_id_declare(app, SCu8("DEFAULT.next_rewrite" )); @@ -395,8 +390,7 @@ default_4coder_initialize(Application_Links *app, char **command_line_files, i32 attachment_tokens = managed_id_declare(app, SCu8("DEFAULT.tokens")); // open command line files - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app); String_Const_u8 hot_directory = push_hot_directory(app, scratch); for (i32 i = 0; i < file_count; i += 1){ Temp_Memory temp2 = begin_temp(scratch); @@ -408,7 +402,6 @@ default_4coder_initialize(Application_Links *app, char **command_line_files, i32 } end_temp(temp2); } - end_temp(temp); } static void diff --git a/4coder_default_framework_variables.cpp b/4coder_default_framework_variables.cpp index b34744ec..fa3bdd7f 100644 --- a/4coder_default_framework_variables.cpp +++ b/4coder_default_framework_variables.cpp @@ -75,7 +75,7 @@ global i32 fcoder_mode = FCoderMode_Original; global ID_Pos_Jump_Location prev_location = {}; -global Arena global_config_arena = {}; +global Arena *global_config_arena = {}; global Config_Data global_config = {}; global char previous_isearch_query[256] = {}; diff --git a/4coder_default_hooks.cpp b/4coder_default_hooks.cpp index acb827ce..768ec0ad 100644 --- a/4coder_default_hooks.cpp +++ b/4coder_default_hooks.cpp @@ -962,7 +962,7 @@ BUFFER_HOOK_SIG(default_file_settings){ String_Const_u8_Array extensions = global_config.code_exts; - Scratch_Block scratch = context_get_arena(app); + Scratch_Block scratch(app); String_Const_u8 file_name = push_buffer_file_name(app, scratch, buffer_id); diff --git a/4coder_experiments.cpp b/4coder_experiments.cpp index 5958112b..3f8e2999 100644 --- a/4coder_experiments.cpp +++ b/4coder_experiments.cpp @@ -70,43 +70,41 @@ multi_paste_range(Application_Links *app, View_ID view, Range_i64 range, i32 pas } total_size -= 1; - if (total_size <= app->memory_size){ - i32 first = paste_count - 1; - i32 one_past_last = -1; - i32 step = -1; - if (!old_to_new){ - first = 0; - one_past_last = paste_count; - step = 1; - } - - List_String_Const_u8 list = {}; - - for (i32 paste_index = first; paste_index != one_past_last; paste_index += step){ - if (paste_index != first){ - string_list_push(scratch, &list, SCu8("\n", 1)); - } - String_Const_u8 string = push_clipboard_index(app, scratch, 0, paste_index); - if (string.size > 0){ - string_list_push(scratch, &list, string); - } - } - - String_Const_u8 flattened = string_list_flatten(scratch, list); - - buffer_replace_range(app, buffer, range, flattened); - i64 pos = range.min; - finish_range.min = pos; - finish_range.max = pos + total_size; - view_set_mark(app, view, seek_pos(finish_range.min)); - view_set_cursor_and_preferred_x(app, view, seek_pos(finish_range.max)); - - // TODO(allen): Send this to all views. - Theme_Color paste; - paste.tag = Stag_Paste; - get_theme_colors(app, &paste, 1); - view_post_fade(app, view, 0.667f, finish_range, paste.color); + i32 first = paste_count - 1; + i32 one_past_last = -1; + i32 step = -1; + if (!old_to_new){ + first = 0; + one_past_last = paste_count; + step = 1; } + + List_String_Const_u8 list = {}; + + for (i32 paste_index = first; paste_index != one_past_last; paste_index += step){ + if (paste_index != first){ + string_list_push(scratch, &list, SCu8("\n", 1)); + } + String_Const_u8 string = push_clipboard_index(app, scratch, 0, paste_index); + if (string.size > 0){ + string_list_push(scratch, &list, string); + } + } + + String_Const_u8 flattened = string_list_flatten(scratch, list); + + buffer_replace_range(app, buffer, range, flattened); + i64 pos = range.min; + finish_range.min = pos; + finish_range.max = pos + total_size; + view_set_mark(app, view, seek_pos(finish_range.min)); + view_set_cursor_and_preferred_x(app, view, seek_pos(finish_range.max)); + + // TODO(allen): Send this to all views. + Theme_Color paste; + paste.tag = Stag_Paste; + get_theme_colors(app, &paste, 1); + view_post_fade(app, view, 0.667f, finish_range, paste.color); } } return(finish_range); diff --git a/4coder_generated/app_functions.h b/4coder_generated/app_functions.h index 940dfc43..c6137b5e 100644 --- a/4coder_generated/app_functions.h +++ b/4coder_generated/app_functions.h @@ -2,8 +2,7 @@ struct Application_Links; #define GLOBAL_SET_SETTING_SIG(n) b32 n(Application_Links *app, Global_Setting_ID setting, i32 value) #define GLOBAL_SET_MAPPING_SIG(n) b32 n(Application_Links *app, void *data, i32 size) #define GLOBAL_GET_SCREEN_RECTANGLE_SIG(n) Rect_f32 n(Application_Links *app) -#define CONTEXT_GET_ARENA_SIG(n) Arena* n(Application_Links *app) -#define CONTEXT_GET_BASE_ALLOCATOR_SIG(n) Base_Allocator* n(Application_Links *app) +#define GET_THREAD_CONTEXT_SIG(n) Thread_Context* n(Application_Links *app) #define CREATE_CHILD_PROCESS_SIG(n) b32 n(Application_Links *app, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *child_process_id_out) #define CHILD_PROCESS_SET_TARGET_BUFFER_SIG(n) b32 n(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags) #define BUFFER_GET_ATTACHED_CHILD_PROCESS_SIG(n) Child_Process_ID n(Application_Links *app, Buffer_ID buffer_id) @@ -184,8 +183,7 @@ struct Application_Links; typedef GLOBAL_SET_SETTING_SIG(Global_Set_Setting_Function); typedef GLOBAL_SET_MAPPING_SIG(Global_Set_Mapping_Function); typedef GLOBAL_GET_SCREEN_RECTANGLE_SIG(Global_Get_Screen_Rectangle_Function); -typedef CONTEXT_GET_ARENA_SIG(Context_Get_Arena_Function); -typedef CONTEXT_GET_BASE_ALLOCATOR_SIG(Context_Get_Base_Allocator_Function); +typedef GET_THREAD_CONTEXT_SIG(Get_Thread_Context_Function); typedef CREATE_CHILD_PROCESS_SIG(Create_Child_Process_Function); typedef CHILD_PROCESS_SET_TARGET_BUFFER_SIG(Child_Process_Set_Target_Buffer_Function); typedef BUFFER_GET_ATTACHED_CHILD_PROCESS_SIG(Buffer_Get_Attached_Child_Process_Function); @@ -367,8 +365,7 @@ struct Application_Links{ Global_Set_Setting_Function *global_set_setting_; Global_Set_Mapping_Function *global_set_mapping_; Global_Get_Screen_Rectangle_Function *global_get_screen_rectangle_; - Context_Get_Arena_Function *context_get_arena_; - Context_Get_Base_Allocator_Function *context_get_base_allocator_; + Get_Thread_Context_Function *get_thread_context_; Create_Child_Process_Function *create_child_process_; Child_Process_Set_Target_Buffer_Function *child_process_set_target_buffer_; Buffer_Get_Attached_Child_Process_Function *buffer_get_attached_child_process_; @@ -546,8 +543,6 @@ struct Application_Links{ Open_Color_Picker_Function *open_color_picker_; Animate_In_N_Milliseconds_Function *animate_in_n_milliseconds_; Buffer_Find_All_Matches_Function *buffer_find_all_matches_; - void *memory; - int32_t memory_size; void *cmd_context; void *system_links; void *current_coroutine; @@ -557,8 +552,7 @@ struct Application_Links{ app_links->global_set_setting_ = Global_Set_Setting;\ app_links->global_set_mapping_ = Global_Set_Mapping;\ app_links->global_get_screen_rectangle_ = Global_Get_Screen_Rectangle;\ - app_links->context_get_arena_ = Context_Get_Arena;\ - app_links->context_get_base_allocator_ = Context_Get_Base_Allocator;\ + app_links->get_thread_context_ = Get_Thread_Context;\ app_links->create_child_process_ = Create_Child_Process;\ app_links->child_process_set_target_buffer_ = Child_Process_Set_Target_Buffer;\ app_links->buffer_get_attached_child_process_ = Buffer_Get_Attached_Child_Process;\ @@ -740,8 +734,7 @@ struct Application_Links{ static b32 global_set_setting(Application_Links *app, Global_Setting_ID setting, i32 value){return(app->global_set_setting_(app, setting, value));} static b32 global_set_mapping(Application_Links *app, void *data, i32 size){return(app->global_set_mapping_(app, data, size));} static Rect_f32 global_get_screen_rectangle(Application_Links *app){return(app->global_get_screen_rectangle_(app));} -static Arena* context_get_arena(Application_Links *app){return(app->context_get_arena_(app));} -static Base_Allocator* context_get_base_allocator(Application_Links *app){return(app->context_get_base_allocator_(app));} +static Thread_Context* get_thread_context(Application_Links *app){return(app->get_thread_context_(app));} static b32 create_child_process(Application_Links *app, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *child_process_id_out){return(app->create_child_process_(app, path, command, child_process_id_out));} static b32 child_process_set_target_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags){return(app->child_process_set_target_buffer_(app, child_process_id, buffer_id, flags));} static Child_Process_ID buffer_get_attached_child_process(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_get_attached_child_process_(app, buffer_id));} diff --git a/4coder_generated/command_metadata.h b/4coder_generated/command_metadata.h index c8bea52d..63fbf623 100644 --- a/4coder_generated/command_metadata.h +++ b/4coder_generated/command_metadata.h @@ -254,20 +254,20 @@ static Command_Metadata fcoder_metacmd_table[226] = { { PROC_LINKS(seek_end_of_line, 0), "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "w:\\4ed\\code\\4coder_seek.cpp", 27, 47 }, { PROC_LINKS(goto_beginning_of_file, 0), "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "w:\\4ed\\code\\4coder_seek.cpp", 27, 53 }, { PROC_LINKS(goto_end_of_file, 0), "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "w:\\4ed\\code\\4coder_seek.cpp", 27, 61 }, -{ PROC_LINKS(change_active_panel, 0), "change_active_panel", 19, "Change the currently active panel, moving to the panel with the next highest view_id.", 85, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 201 }, -{ PROC_LINKS(change_active_panel_backwards, 0), "change_active_panel_backwards", 29, "Change the currently active panel, moving to the panel with the next lowest view_id.", 84, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 211 }, -{ PROC_LINKS(open_panel_vsplit, 0), "open_panel_vsplit", 17, "Create a new panel by vertically splitting the active panel.", 60, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 221 }, -{ PROC_LINKS(open_panel_hsplit, 0), "open_panel_hsplit", 17, "Create a new panel by horizontally splitting the active panel.", 62, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 231 }, -{ PROC_LINKS(suppress_mouse, 0), "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 294 }, -{ PROC_LINKS(allow_mouse, 0), "allow_mouse", 11, "Shows the mouse and causes all mouse input to be processed normally.", 68, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 300 }, -{ PROC_LINKS(toggle_mouse, 0), "toggle_mouse", 12, "Toggles the mouse suppression mode, see suppress_mouse and allow_mouse.", 71, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 306 }, -{ PROC_LINKS(set_mode_to_original, 0), "set_mode_to_original", 20, "Sets the edit mode to 4coder original.", 38, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 312 }, -{ PROC_LINKS(set_mode_to_notepad_like, 0), "set_mode_to_notepad_like", 24, "Sets the edit mode to Notepad like.", 35, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 318 }, -{ PROC_LINKS(toggle_highlight_line_at_cursor, 0), "toggle_highlight_line_at_cursor", 31, "Toggles the line highlight at the cursor.", 41, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 324 }, -{ PROC_LINKS(toggle_highlight_enclosing_scopes, 0), "toggle_highlight_enclosing_scopes", 33, "In code files scopes surrounding the cursor are highlighted with distinguishing colors.", 87, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 330 }, -{ PROC_LINKS(toggle_paren_matching_helper, 0), "toggle_paren_matching_helper", 28, "In code files matching parentheses pairs are colored with distinguishing colors.", 80, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 336 }, -{ PROC_LINKS(toggle_fullscreen, 0), "toggle_fullscreen", 17, "Toggle fullscreen mode on or off. The change(s) do not take effect until the next frame.", 89, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 342 }, -{ PROC_LINKS(remap_interactive, 0), "remap_interactive", 17, "Switch to a named key binding map.", 34, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 350 }, +{ PROC_LINKS(change_active_panel, 0), "change_active_panel", 19, "Change the currently active panel, moving to the panel with the next highest view_id.", 85, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 196 }, +{ PROC_LINKS(change_active_panel_backwards, 0), "change_active_panel_backwards", 29, "Change the currently active panel, moving to the panel with the next lowest view_id.", 84, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 206 }, +{ PROC_LINKS(open_panel_vsplit, 0), "open_panel_vsplit", 17, "Create a new panel by vertically splitting the active panel.", 60, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 216 }, +{ PROC_LINKS(open_panel_hsplit, 0), "open_panel_hsplit", 17, "Create a new panel by horizontally splitting the active panel.", 62, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 226 }, +{ PROC_LINKS(suppress_mouse, 0), "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 289 }, +{ PROC_LINKS(allow_mouse, 0), "allow_mouse", 11, "Shows the mouse and causes all mouse input to be processed normally.", 68, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 295 }, +{ PROC_LINKS(toggle_mouse, 0), "toggle_mouse", 12, "Toggles the mouse suppression mode, see suppress_mouse and allow_mouse.", 71, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 301 }, +{ PROC_LINKS(set_mode_to_original, 0), "set_mode_to_original", 20, "Sets the edit mode to 4coder original.", 38, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 307 }, +{ PROC_LINKS(set_mode_to_notepad_like, 0), "set_mode_to_notepad_like", 24, "Sets the edit mode to Notepad like.", 35, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 313 }, +{ PROC_LINKS(toggle_highlight_line_at_cursor, 0), "toggle_highlight_line_at_cursor", 31, "Toggles the line highlight at the cursor.", 41, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 319 }, +{ PROC_LINKS(toggle_highlight_enclosing_scopes, 0), "toggle_highlight_enclosing_scopes", 33, "In code files scopes surrounding the cursor are highlighted with distinguishing colors.", 87, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 325 }, +{ PROC_LINKS(toggle_paren_matching_helper, 0), "toggle_paren_matching_helper", 28, "In code files matching parentheses pairs are colored with distinguishing colors.", 80, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 331 }, +{ PROC_LINKS(toggle_fullscreen, 0), "toggle_fullscreen", 17, "Toggle fullscreen mode on or off. The change(s) do not take effect until the next frame.", 89, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 337 }, +{ PROC_LINKS(remap_interactive, 0), "remap_interactive", 17, "Switch to a named key binding map.", 34, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 345 }, { PROC_LINKS(write_character, 0), "write_character", 15, "Inserts whatever character was used to trigger this command.", 60, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 57 }, { PROC_LINKS(write_underscore, 0), "write_underscore", 16, "Inserts an underscore.", 22, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 66 }, { PROC_LINKS(delete_char, 0), "delete_char", 11, "Deletes the character to the right of the cursor.", 49, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 73 }, @@ -346,24 +346,24 @@ static Command_Metadata fcoder_metacmd_table[226] = { { PROC_LINKS(save_all_dirty_buffers, 0), "save_all_dirty_buffers", 22, "Saves all buffers marked dirty (showing the '*' indicator).", 59, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1251 }, { PROC_LINKS(delete_file_query, 0), "delete_file_query", 17, "Deletes the file of the current buffer if 4coder has the appropriate access rights. Will ask the user for confirmation first.", 125, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1276 }, { PROC_LINKS(save_to_query, 0), "save_to_query", 13, "Queries the user for a file name and saves the contents of the current buffer, altering the buffer's name too.", 110, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1314 }, -{ PROC_LINKS(rename_file_query, 0), "rename_file_query", 17, "Queries the user for a new name and renames the file of the current buffer, altering the buffer's name too.", 107, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1349 }, -{ PROC_LINKS(make_directory_query, 0), "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1389 }, -{ PROC_LINKS(move_line_up, 0), "move_line_up", 12, "Swaps the line under the cursor with the line above it, and moves the cursor up with it.", 88, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1422 }, -{ PROC_LINKS(move_line_down, 0), "move_line_down", 14, "Swaps the line under the cursor with the line below it, and moves the cursor down with it.", 90, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1428 }, -{ PROC_LINKS(duplicate_line, 0), "duplicate_line", 14, "Create a copy of the line on which the cursor sits.", 51, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1434 }, -{ PROC_LINKS(delete_line, 0), "delete_line", 11, "Delete the line the on which the cursor sits.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1448 }, -{ PROC_LINKS(open_file_in_quotes, 0), "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1513 }, -{ PROC_LINKS(open_matching_file_cpp, 0), "open_matching_file_cpp", 22, "If the current file is a *.cpp or *.h, attempts to open the corresponding *.h or *.cpp file in the other view.", 110, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1545 }, -{ PROC_LINKS(view_buffer_other_panel, 0), "view_buffer_other_panel", 23, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1558 }, -{ PROC_LINKS(swap_buffers_between_panels, 0), "swap_buffers_between_panels", 27, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1570 }, -{ PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1606 }, -{ PROC_LINKS(save, 0), "save", 4, "Saves the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1614 }, -{ PROC_LINKS(reopen, 0), "reopen", 6, "Reopen the current buffer from the hard drive.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1626 }, -{ PROC_LINKS(undo, 0), "undo", 4, "Advances backwards through the undo history of the current buffer.", 66, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1684 }, -{ PROC_LINKS(redo, 0), "redo", 4, "Advances forwards through the undo history of the current buffer.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1697 }, -{ PROC_LINKS(undo_all_buffers, 0), "undo_all_buffers", 16, "Advances backward through the undo history in the buffer containing the most recent regular edit.", 97, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1711 }, -{ PROC_LINKS(redo_all_buffers, 0), "redo_all_buffers", 16, "Advances forward through the undo history in the buffer containing the most recent regular edit.", 96, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1785 }, -{ PROC_LINKS(open_in_other, 0), "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1888 }, +{ PROC_LINKS(rename_file_query, 0), "rename_file_query", 17, "Queries the user for a new name and renames the file of the current buffer, altering the buffer's name too.", 107, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1346 }, +{ PROC_LINKS(make_directory_query, 0), "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1383 }, +{ PROC_LINKS(move_line_up, 0), "move_line_up", 12, "Swaps the line under the cursor with the line above it, and moves the cursor up with it.", 88, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1416 }, +{ PROC_LINKS(move_line_down, 0), "move_line_down", 14, "Swaps the line under the cursor with the line below it, and moves the cursor down with it.", 90, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1422 }, +{ PROC_LINKS(duplicate_line, 0), "duplicate_line", 14, "Create a copy of the line on which the cursor sits.", 51, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1428 }, +{ PROC_LINKS(delete_line, 0), "delete_line", 11, "Delete the line the on which the cursor sits.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1442 }, +{ PROC_LINKS(open_file_in_quotes, 0), "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1507 }, +{ PROC_LINKS(open_matching_file_cpp, 0), "open_matching_file_cpp", 22, "If the current file is a *.cpp or *.h, attempts to open the corresponding *.h or *.cpp file in the other view.", 110, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1539 }, +{ PROC_LINKS(view_buffer_other_panel, 0), "view_buffer_other_panel", 23, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1552 }, +{ PROC_LINKS(swap_buffers_between_panels, 0), "swap_buffers_between_panels", 27, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1564 }, +{ PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1600 }, +{ PROC_LINKS(save, 0), "save", 4, "Saves the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1608 }, +{ PROC_LINKS(reopen, 0), "reopen", 6, "Reopen the current buffer from the hard drive.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1618 }, +{ PROC_LINKS(undo, 0), "undo", 4, "Advances backwards through the undo history of the current buffer.", 66, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1676 }, +{ PROC_LINKS(redo, 0), "redo", 4, "Advances forwards through the undo history of the current buffer.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1689 }, +{ PROC_LINKS(undo_all_buffers, 0), "undo_all_buffers", 16, "Advances backward through the undo history in the buffer containing the most recent regular edit.", 97, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1703 }, +{ PROC_LINKS(redo_all_buffers, 0), "redo_all_buffers", 16, "Advances forward through the undo history in the buffer containing the most recent regular edit.", 96, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1774 }, +{ PROC_LINKS(open_in_other, 0), "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1875 }, { PROC_LINKS(lister__quit, 0), "lister__quit", 12, "A lister mode command that quits the list without executing any actions.", 72, "w:\\4ed\\code\\4coder_lists.cpp", 28, 8 }, { PROC_LINKS(lister__activate, 0), "lister__activate", 16, "A lister mode command that activates the list's action on the highlighted item.", 79, "w:\\4ed\\code\\4coder_lists.cpp", 28, 15 }, { PROC_LINKS(lister__write_character, 0), "lister__write_character", 23, "A lister mode command that dispatches to the lister's write character handler.", 78, "w:\\4ed\\code\\4coder_lists.cpp", 28, 30 }, @@ -381,12 +381,12 @@ static Command_Metadata fcoder_metacmd_table[226] = { { PROC_LINKS(lister__write_character__file_path, 0), "lister__write_character__file_path", 34, "A lister mode command that inserts a character into the text field of a file system list.", 89, "w:\\4ed\\code\\4coder_lists.cpp", 28, 183 }, { PROC_LINKS(lister__backspace_text_field__file_path, 0), "lister__backspace_text_field__file_path", 39, "A lister mode command that backspaces one character from the text field of a file system list.", 94, "w:\\4ed\\code\\4coder_lists.cpp", 28, 208 }, { PROC_LINKS(lister__write_character__fixed_list, 0), "lister__write_character__fixed_list", 35, "A lister mode command that handles input for the fixed sure to kill list.", 73, "w:\\4ed\\code\\4coder_lists.cpp", 28, 249 }, -{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "w:\\4ed\\code\\4coder_lists.cpp", 28, 723 }, -{ PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\4coder_lists.cpp", 28, 742 }, -{ PROC_LINKS(interactive_open_or_new, 0), "interactive_open_or_new", 23, "Interactively open a file out of the file system.", 49, "w:\\4ed\\code\\4coder_lists.cpp", 28, 815 }, -{ PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\4coder_lists.cpp", 28, 854 }, -{ PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\4coder_lists.cpp", 28, 887 }, -{ PROC_LINKS(command_lister, 0), "command_lister", 14, "Opens an interactive list of all registered commands.", 53, "w:\\4ed\\code\\4coder_lists.cpp", 28, 969 }, +{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "w:\\4ed\\code\\4coder_lists.cpp", 28, 718 }, +{ PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\4coder_lists.cpp", 28, 737 }, +{ PROC_LINKS(interactive_open_or_new, 0), "interactive_open_or_new", 23, "Interactively open a file out of the file system.", 49, "w:\\4ed\\code\\4coder_lists.cpp", 28, 808 }, +{ PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\4coder_lists.cpp", 28, 847 }, +{ PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\4coder_lists.cpp", 28, 880 }, +{ PROC_LINKS(command_lister, 0), "command_lister", 14, "Opens an interactive list of all registered commands.", 53, "w:\\4ed\\code\\4coder_lists.cpp", 28, 960 }, { PROC_LINKS(auto_tab_whole_file, 0), "auto_tab_whole_file", 19, "Audo-indents the entire current buffer.", 39, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 500 }, { PROC_LINKS(auto_tab_line_at_cursor, 0), "auto_tab_line_at_cursor", 23, "Auto-indents the line on which the cursor sits.", 47, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 509 }, { PROC_LINKS(auto_tab_range, 0), "auto_tab_range", 14, "Auto-indents the range between the cursor and the mark.", 55, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 519 }, @@ -401,18 +401,18 @@ static Command_Metadata fcoder_metacmd_table[226] = { { PROC_LINKS(list_all_locations_of_selection_case_insensitive, 0), "list_all_locations_of_selection_case_insensitive", 48, "Reads the string in the selected range and lists all exact case-insensitive mathces in all open buffers.", 104, "w:\\4ed\\code\\4coder_search.cpp", 29, 208 }, { PROC_LINKS(list_all_locations_of_type_definition, 0), "list_all_locations_of_type_definition", 37, "Queries user for string, lists all locations of strings that appear to define a type whose name matches the input string.", 121, "w:\\4ed\\code\\4coder_search.cpp", 29, 214 }, { PROC_LINKS(list_all_locations_of_type_definition_of_identifier, 0), "list_all_locations_of_type_definition_of_identifier", 51, "Reads a token or word under the cursor and lists all locations of strings that appear to define a type whose name matches it.", 125, "w:\\4ed\\code\\4coder_search.cpp", 29, 222 }, -{ PROC_LINKS(word_complete, 0), "word_complete", 13, "Iteratively tries completing the word to the left of the cursor with other words in open buffers that have the same prefix string.", 130, "w:\\4ed\\code\\4coder_search.cpp", 29, 376 }, -{ PROC_LINKS(goto_jump_at_cursor, 0), "goto_jump_at_cursor", 19, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 353 }, -{ PROC_LINKS(goto_jump_at_cursor_same_panel, 0), "goto_jump_at_cursor_same_panel", 30, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list.", 167, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 380 }, -{ PROC_LINKS(goto_next_jump, 0), "goto_next_jump", 14, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.", 123, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 469 }, -{ PROC_LINKS(goto_prev_jump, 0), "goto_prev_jump", 14, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations.", 127, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 486 }, -{ PROC_LINKS(goto_next_jump_no_skips, 0), "goto_next_jump_no_skips", 23, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.", 132, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 499 }, -{ PROC_LINKS(goto_prev_jump_no_skips, 0), "goto_prev_jump_no_skips", 23, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 516 }, -{ PROC_LINKS(goto_first_jump, 0), "goto_first_jump", 15, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 530 }, -{ PROC_LINKS(goto_first_jump_same_panel_sticky, 0), "goto_first_jump_same_panel_sticky", 33, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer and views the buffer in the panel where the jump list was.", 153, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 547 }, -{ PROC_LINKS(newline_or_goto_position, 0), "newline_or_goto_position", 24, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 569 }, -{ PROC_LINKS(newline_or_goto_position_same_panel, 0), "newline_or_goto_position_same_panel", 35, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 586 }, -{ PROC_LINKS(view_jump_list_with_lister, 0), "view_jump_list_with_lister", 26, "When executed on a buffer with jumps, creates a persistent lister for all the jumps", 83, "w:\\4ed\\code\\4coder_jump_lister.cpp", 34, 104 }, +{ PROC_LINKS(word_complete, 0), "word_complete", 13, "Iteratively tries completing the word to the left of the cursor with other words in open buffers that have the same prefix string.", 130, "w:\\4ed\\code\\4coder_search.cpp", 29, 378 }, +{ PROC_LINKS(goto_jump_at_cursor, 0), "goto_jump_at_cursor", 19, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 346 }, +{ PROC_LINKS(goto_jump_at_cursor_same_panel, 0), "goto_jump_at_cursor_same_panel", 30, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list.", 167, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 373 }, +{ PROC_LINKS(goto_next_jump, 0), "goto_next_jump", 14, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.", 123, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 462 }, +{ PROC_LINKS(goto_prev_jump, 0), "goto_prev_jump", 14, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations.", 127, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 479 }, +{ PROC_LINKS(goto_next_jump_no_skips, 0), "goto_next_jump_no_skips", 23, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.", 132, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 492 }, +{ PROC_LINKS(goto_prev_jump_no_skips, 0), "goto_prev_jump_no_skips", 23, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 509 }, +{ PROC_LINKS(goto_first_jump, 0), "goto_first_jump", 15, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 523 }, +{ PROC_LINKS(goto_first_jump_same_panel_sticky, 0), "goto_first_jump_same_panel_sticky", 33, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer and views the buffer in the panel where the jump list was.", 153, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 540 }, +{ PROC_LINKS(newline_or_goto_position, 0), "newline_or_goto_position", 24, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 562 }, +{ PROC_LINKS(newline_or_goto_position_same_panel, 0), "newline_or_goto_position_same_panel", 35, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 579 }, +{ PROC_LINKS(view_jump_list_with_lister, 0), "view_jump_list_with_lister", 26, "When executed on a buffer with jumps, creates a persistent lister for all the jumps", 83, "w:\\4ed\\code\\4coder_jump_lister.cpp", 34, 102 }, { PROC_LINKS(log_graph__escape, 0), "log_graph__escape", 17, "Ends the log grapher", 20, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 906 }, { PROC_LINKS(log_graph__scroll_wheel, 0), "log_graph__scroll_wheel", 23, "Scrolls the log graph", 21, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 915 }, { PROC_LINKS(log_graph__page_up, 0), "log_graph__page_up", 18, "Scroll the log graph up one whole page", 38, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 926 }, @@ -432,17 +432,17 @@ static Command_Metadata fcoder_metacmd_table[226] = { { PROC_LINKS(build_in_build_panel, 0), "build_in_build_panel", 20, "Looks for a build.bat, build.sh, or makefile in the current and parent directories. Runs the first that it finds and prints the output to *compilation*. Puts the *compilation* buffer in a panel at the footer of the current view.", 230, "w:\\4ed\\code\\4coder_build_commands.cpp", 37, 163 }, { PROC_LINKS(close_build_panel, 0), "close_build_panel", 17, "If the special build panel is open, closes it.", 46, "w:\\4ed\\code\\4coder_build_commands.cpp", 37, 178 }, { PROC_LINKS(change_to_build_panel, 0), "change_to_build_panel", 21, "If the special build panel is open, makes the build panel the active panel.", 75, "w:\\4ed\\code\\4coder_build_commands.cpp", 37, 184 }, -{ PROC_LINKS(close_all_code, 0), "close_all_code", 14, "Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.", 107, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 921 }, -{ PROC_LINKS(open_all_code, 0), "open_all_code", 13, "Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.", 164, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 927 }, -{ PROC_LINKS(open_all_code_recursive, 0), "open_all_code_recursive", 23, "Works as open_all_code but also runs in all subdirectories.", 59, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 933 }, -{ PROC_LINKS(load_project, 0), "load_project", 12, "Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.", 167, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 941 }, -{ PROC_LINKS(project_fkey_command, 0), "project_fkey_command", 20, "Run an 'fkey command' configured in a project.4coder file. Determines the index of the 'fkey command' by which function key or numeric key was pressed to trigger the command.", 175, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 948 }, -{ PROC_LINKS(project_go_to_root_directory, 0), "project_go_to_root_directory", 28, "Changes 4coder's hot directory to the root directory of the currently loaded project. With no loaded project nothing hapepns.", 125, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 971 }, -{ PROC_LINKS(setup_new_project, 0), "setup_new_project", 17, "Queries the user for several configuration options and initializes a new 4coder project with build scripts for every OS.", 120, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1306 }, -{ PROC_LINKS(setup_build_bat, 0), "setup_build_bat", 15, "Queries the user for several configuration options and initializes a new build batch script.", 92, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1313 }, -{ PROC_LINKS(setup_build_sh, 0), "setup_build_sh", 14, "Queries the user for several configuration options and initializes a new build shell script.", 92, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1319 }, -{ PROC_LINKS(setup_build_bat_and_sh, 0), "setup_build_bat_and_sh", 22, "Queries the user for several configuration options and initializes a new build batch script.", 92, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1325 }, -{ PROC_LINKS(project_command_lister, 0), "project_command_lister", 22, "Open a lister of all commands in the currently loaded project.", 62, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1340 }, +{ PROC_LINKS(close_all_code, 0), "close_all_code", 14, "Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.", 107, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 917 }, +{ PROC_LINKS(open_all_code, 0), "open_all_code", 13, "Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.", 164, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 923 }, +{ PROC_LINKS(open_all_code_recursive, 0), "open_all_code_recursive", 23, "Works as open_all_code but also runs in all subdirectories.", 59, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 929 }, +{ PROC_LINKS(load_project, 0), "load_project", 12, "Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.", 167, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 937 }, +{ PROC_LINKS(project_fkey_command, 0), "project_fkey_command", 20, "Run an 'fkey command' configured in a project.4coder file. Determines the index of the 'fkey command' by which function key or numeric key was pressed to trigger the command.", 175, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 944 }, +{ PROC_LINKS(project_go_to_root_directory, 0), "project_go_to_root_directory", 28, "Changes 4coder's hot directory to the root directory of the currently loaded project. With no loaded project nothing hapepns.", 125, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 967 }, +{ PROC_LINKS(setup_new_project, 0), "setup_new_project", 17, "Queries the user for several configuration options and initializes a new 4coder project with build scripts for every OS.", 120, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1299 }, +{ PROC_LINKS(setup_build_bat, 0), "setup_build_bat", 15, "Queries the user for several configuration options and initializes a new build batch script.", 92, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1306 }, +{ PROC_LINKS(setup_build_sh, 0), "setup_build_sh", 14, "Queries the user for several configuration options and initializes a new build shell script.", 92, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1312 }, +{ PROC_LINKS(setup_build_bat_and_sh, 0), "setup_build_bat_and_sh", 22, "Queries the user for several configuration options and initializes a new build batch script.", 92, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1318 }, +{ PROC_LINKS(project_command_lister, 0), "project_command_lister", 22, "Open a lister of all commands in the currently loaded project.", 62, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1333 }, { PROC_LINKS(list_all_functions_current_buffer, 0), "list_all_functions_current_buffer", 33, "Creates a jump list of lines of the current buffer that appear to define or declare functions.", 94, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 267 }, { PROC_LINKS(list_all_functions_current_buffer_lister, 0), "list_all_functions_current_buffer_lister", 40, "Creates a lister of locations that look like function definitions and declarations in the buffer.", 97, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 277 }, { PROC_LINKS(list_all_functions_all_buffers, 0), "list_all_functions_all_buffers", 30, "Creates a jump list of lines from all buffers that appear to define or declare functions.", 89, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 289 }, @@ -464,10 +464,10 @@ static Command_Metadata fcoder_metacmd_table[226] = { { PROC_LINKS(comment_line, 0), "comment_line", 12, "Insert '//' at the beginning of the line after leading whitespace.", 66, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 125 }, { PROC_LINKS(uncomment_line, 0), "uncomment_line", 14, "If present, delete '//' at the beginning of the line after leading whitespace.", 78, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 137 }, { PROC_LINKS(comment_line_toggle, 0), "comment_line_toggle", 19, "Turns uncommented lines into commented lines and vice versa for comments starting with '//'.", 92, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 149 }, -{ PROC_LINKS(snippet_lister, 0), "snippet_lister", 14, "Opens a snippet lister for inserting whole pre-written snippets of text.", 72, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 235 }, +{ PROC_LINKS(snippet_lister, 0), "snippet_lister", 14, "Opens a snippet lister for inserting whole pre-written snippets of text.", 72, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 233 }, { PROC_LINKS(set_bindings_choose, 0), "set_bindings_choose", 19, "Remap keybindings using the 'choose' mapping rule.", 50, "w:\\4ed\\code\\4coder_remapping_commands.cpp", 41, 41 }, { PROC_LINKS(set_bindings_default, 0), "set_bindings_default", 20, "Remap keybindings using the 'default' mapping rule.", 51, "w:\\4ed\\code\\4coder_remapping_commands.cpp", 41, 51 }, -{ PROC_LINKS(set_bindings_mac_default, 0), "set_bindings_mac_default", 24, "Remap keybindings using the 'mac-default' mapping rule.", 55, "w:\\4ed\\code\\4coder_remapping_commands.cpp", 41, 66 }, +{ PROC_LINKS(set_bindings_mac_default, 0), "set_bindings_mac_default", 24, "Remap keybindings using the 'mac-default' mapping rule.", 55, "w:\\4ed\\code\\4coder_remapping_commands.cpp", 41, 62 }, { PROC_LINKS(miblo_increment_basic, 0), "miblo_increment_basic", 21, "Increment an integer under the cursor by one.", 45, "w:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 29 }, { PROC_LINKS(miblo_decrement_basic, 0), "miblo_decrement_basic", 21, "Decrement an integer under the cursor by one.", 45, "w:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 44 }, { PROC_LINKS(miblo_increment_time_stamp, 0), "miblo_increment_time_stamp", 26, "Increment a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 231 }, diff --git a/4coder_insertion.cpp b/4coder_insertion.cpp index 0514bae9..6d650270 100644 --- a/4coder_insertion.cpp +++ b/4coder_insertion.cpp @@ -88,14 +88,12 @@ insert_string(Buffer_Insertion *insertion, String_Const_u8 string){ static umem insertf(Buffer_Insertion *insertion, char *format, ...){ - Arena *scratch = context_get_arena(insertion->app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(insertion->app); va_list args; va_start(args, format); String_Const_u8 string = push_u8_stringfv(scratch, format, args); va_end(args); insert_string(insertion, string); - end_temp(temp); return(string.size); } diff --git a/4coder_jump_lister.cpp b/4coder_jump_lister.cpp index 8503f201..170af226 100644 --- a/4coder_jump_lister.cpp +++ b/4coder_jump_lister.cpp @@ -68,8 +68,7 @@ open_jump_lister(Application_Links *app, Heap *heap, View_ID ui_view, Buffer_ID if (list != 0){ i32 estimated_string_space_size = 0; view_end_ui_mode(app, ui_view); - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app); i32 option_count = list->jump_count; Lister_Option *options = push_array(scratch, Lister_Option, option_count); Managed_Object stored_jumps = list->jump_array; @@ -97,7 +96,6 @@ open_jump_lister(Application_Links *app, Heap *heap, View_ID ui_view, Buffer_ID options, option_count, estimated_string_space_size, ui_view); - end_temp(temp); } } diff --git a/4coder_jump_sticky.cpp b/4coder_jump_sticky.cpp index 4da5397a..b8045297 100644 --- a/4coder_jump_sticky.cpp +++ b/4coder_jump_sticky.cpp @@ -103,8 +103,7 @@ parse_buffer_to_jump_array(Application_Links *app, Arena *arena, Buffer_ID buffe internal void init_marker_list(Application_Links *app, Heap *heap, Buffer_ID buffer, Marker_List *list){ - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app); Sticky_Jump_Array jumps = parse_buffer_to_jump_array(app, scratch, buffer); Range_Array buffer_ranges = get_ranges_of_duplicate_keys(scratch, &jumps.jumps->jump_buffer_id, sizeof(*jumps.jumps), jumps.count); @@ -182,8 +181,6 @@ init_marker_list(Application_Links *app, Heap *heap, Buffer_ID buffer, Marker_Li list->jump_count = jumps.count; list->previous_size = (i32)buffer_get_size(app, buffer); list->buffer_id = buffer; - - end_temp(temp); } internal void @@ -321,13 +318,11 @@ internal i32 get_index_nearest_from_list(Application_Links *app, Marker_List *list, i64 line){ i32 result = -1; if (list != 0){ - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app); Sticky_Jump_Stored *stored = get_all_stored_jumps_from_list(app, scratch, list); if (stored != 0){ result = binary_search((i64*)&stored->list_line, sizeof(*stored), list->jump_count, line); } - end_temp(temp); } return(result); } @@ -336,8 +331,7 @@ internal i32 get_index_exact_from_list(Application_Links *app, Marker_List *list, i64 line){ i32 result = -1; if (list != 0){ - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app); Sticky_Jump_Stored *stored = get_all_stored_jumps_from_list(app, scratch, list); if (stored != 0){ i32 index = binary_search((i64*)&stored->list_line, sizeof(*stored), list->jump_count, line); @@ -345,7 +339,6 @@ get_index_exact_from_list(Application_Links *app, Marker_List *list, i64 line){ result = index; } } - end_temp(temp); } return(result); } diff --git a/4coder_lists.cpp b/4coder_lists.cpp index 8bff483c..ddeb6731 100644 --- a/4coder_lists.cpp +++ b/4coder_lists.cpp @@ -456,11 +456,9 @@ generate_all_buffers_list__output_buffer(Application_Links *app, Lister *lister, case DirtyState_UnloadedChanges: status = string_u8_litexpr("!"); break; case DirtyState_UnsavedChangesAndUnloadedChanges: status = string_u8_litexpr("*!"); break; } - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app); String_Const_u8 buffer_name = push_buffer_unique_name(app, scratch, buffer); lister_add_item(lister, buffer_name, status, IntAsPtr(buffer), 0); - end_temp(temp); } static void @@ -528,10 +526,10 @@ static void generate_hot_directory_file_list(Application_Links *app, Lister *lister){ Scratch_Block scratch(app); - Temp_Memory temp = begin_temp(&lister->arena); - String_Const_u8 hot = push_hot_directory(app, &lister->arena); + Temp_Memory temp = begin_temp(lister->arena); + String_Const_u8 hot = push_hot_directory(app, lister->arena); if (!character_is_slash(string_get_character(hot, hot.size - 1))){ - hot = push_u8_stringf(&lister->arena, "%.*s/", string_expand(hot)); + hot = push_u8_stringf(lister->arena, "%.*s/", string_expand(hot)); } lister_set_text_field(lister, hot); lister_set_key(lister, string_front_of_path(hot)); @@ -543,8 +541,8 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){ lister_begin_new_item_set(app, lister); - hot = push_hot_directory(app, &lister->arena); - push_align(&lister->arena, 8); + hot = push_hot_directory(app, lister->arena); + push_align(lister->arena, 8); if (hot.str != 0){ String_Const_u8 empty_string = string_u8_litexpr(""); Lister_Prealloced_String empty_string_prealloced = lister_prealloced(empty_string); @@ -552,7 +550,7 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){ info < one_past_last; info += 1){ if (!HasFlag((**info).attributes.flags, FileAttribute_IsDirectory)) continue; - String_Const_u8 file_name = push_u8_stringf(&lister->arena, "%.*s/", + String_Const_u8 file_name = push_u8_stringf(lister->arena, "%.*s/", string_expand((**info).file_name)); lister_add_item(lister, lister_prealloced(file_name), empty_string_prealloced, file_name.str, 0); } @@ -561,18 +559,18 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){ info < one_past_last; info += 1){ if (HasFlag((**info).attributes.flags, FileAttribute_IsDirectory)) continue; - String_Const_u8 file_name = push_string_copy(&lister->arena, (**info).file_name); + String_Const_u8 file_name = push_string_copy(lister->arena, (**info).file_name); char *is_loaded = ""; char *status_flag = ""; Buffer_ID buffer = {}; { - Temp_Memory path_temp = begin_temp(&lister->arena); + Temp_Memory path_temp = begin_temp(lister->arena); List_String_Const_u8 list = {}; - string_list_push(&lister->arena, &list, hot); - string_list_push_overlap(&lister->arena, &list, '/', (**info).file_name); - String_Const_u8 full_file_path = string_list_flatten(&lister->arena, list); + string_list_push(lister->arena, &list, hot); + string_list_push_overlap(lister->arena, &list, '/', (**info).file_name); + String_Const_u8 full_file_path = string_list_flatten(lister->arena, list); buffer = get_buffer_by_file_name(app, full_file_path, AccessAll); end_temp(path_temp); } @@ -586,7 +584,7 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){ case DirtyState_UnsavedChangesAndUnloadedChanges: status_flag = " *!"; break; } } - String_Const_u8 status = push_u8_stringf(&lister->arena, "%s%s", is_loaded, status_flag); + String_Const_u8 status = push_u8_stringf(lister->arena, "%s%s", is_loaded, status_flag); lister_add_item(lister, lister_prealloced(file_name), lister_prealloced(status), file_name.str, 0); } } @@ -636,8 +634,7 @@ activate_confirm_kill(Application_Links *app, Heap *heap, View_ID view, Lister_S case SureToKill_Save: { - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app); String_Const_u8 file_name = push_buffer_file_name(app, scratch, buffer_id); if (buffer_save(app, buffer_id, file_name, BufferSave_IgnoreDirtyFlag)){ buffer_kill(app, buffer_id, BufferKill_AlwaysKill); @@ -647,8 +644,6 @@ activate_confirm_kill(Application_Links *app, Heap *heap, View_ID view, Lister_S string_expand(file_name)); print_message(app, str); } - - end_temp(temp); }break; } lister_default(app, heap, view, state, ListerActivation_Finished); @@ -760,8 +755,7 @@ activate_open_or_new__generic(Application_Links *app, View_ID view, result = ListerActivation_Finished; } else{ - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app, Scratch_Share); String_Const_u8 full_file_name = {}; if (character_is_slash(string_get_character(path, path.size - 1))){ path = string_chop(path, 1); @@ -778,7 +772,6 @@ activate_open_or_new__generic(Application_Links *app, View_ID view, } result = ListerActivation_Finished; } - end_temp(temp); } return(result); @@ -947,10 +940,9 @@ launch_custom_command_lister(Application_Links *app, i32 *command_ids, i32 comma command_id_count = command_one_past_last_id; } - Arena *scratch = context_get_arena(app); + Scratch_Block scratch(app, Scratch_Share); View_ID view = get_active_view(app, AccessAll); view_end_ui_mode(app, view); - Temp_Memory temp = begin_temp(scratch); Lister_Option *options = push_array(scratch, Lister_Option, command_id_count); for (i32 i = 0; i < command_id_count; i += 1){ i32 j = i; @@ -963,7 +955,6 @@ launch_custom_command_lister(Application_Links *app, i32 *command_ids, i32 comma options[i].user_data = (void*)fcoder_metacmd_table[j].proc; } begin_integrated_lister__basic_list(app, "Command:", activate_command, 0, 0, options, command_id_count, 0, view); - end_temp(temp); } CUSTOM_COMMAND_SIG(command_lister) diff --git a/4coder_log_parser.cpp b/4coder_log_parser.cpp index a41c9bc7..5b9fc7e9 100644 --- a/4coder_log_parser.cpp +++ b/4coder_log_parser.cpp @@ -367,7 +367,7 @@ log_event_array_from_list(Arena *arena, Log_Event_List list){ //////////////////////////////// global View_ID log_view = 0; -global Arena log_arena = {}; +global Arena *log_arena = {}; global Log_Parse log_parse = {}; global Log_Graph log_graph = {}; global Log_Filter_Set log_filter_set = {}; @@ -438,7 +438,7 @@ log_graph_fill(Application_Links *app, Rect_f32 layout_region, Face_ID face_id){ } block_zero_struct(&log_graph); log_graph.holding_temp = true; - log_graph.temp = begin_temp(&log_arena); + log_graph.temp = begin_temp(log_arena); log_graph.layout_region = layout_region; log_graph.face_id = face_id; log_graph.filter_alter_counter = log_filter_set.alter_counter; @@ -465,7 +465,7 @@ log_graph_fill(Application_Links *app, Rect_f32 layout_region, Face_ID face_id){ for (Log_Event *event = log_parse.first_event; event != 0; event = event->next){ - Log_Event_Ptr_Node *node = push_array(&log_arena, Log_Event_Ptr_Node, 1); + Log_Event_Ptr_Node *node = push_array(log_arena, Log_Event_Ptr_Node, 1); node->event = event; sll_queue_push(log_graph.filtered_list.first, log_graph.filtered_list.last, node); log_graph.filtered_list.count += 1; @@ -489,7 +489,7 @@ log_graph_fill(Application_Links *app, Rect_f32 layout_region, Face_ID face_id){ for (Log_Event_Ptr_Node *node = filter_list->first; node != 0; node = node->next){ - Log_Event_Ptr_Node *new_node = push_array(&log_arena, Log_Event_Ptr_Node, 1); + Log_Event_Ptr_Node *new_node = push_array(log_arena, Log_Event_Ptr_Node, 1); new_node->event = node->event; sll_queue_push(log_graph.filtered_list.first, log_graph.filtered_list.last, new_node); log_graph.filtered_list.count += 1; @@ -525,9 +525,9 @@ log_graph_fill(Application_Links *app, Rect_f32 layout_region, Face_ID face_id){ } } - log_graph.event_array = log_event_array_from_list(&log_arena, + log_graph.event_array = log_event_array_from_list(log_arena, log_graph.filtered_list); - log_events_sort_by_tag(&log_arena, log_graph.event_array, thread_code); + log_events_sort_by_tag(log_arena, log_graph.event_array, thread_code); b32 had_a_tag = true; u64 thread_id_value = 0; @@ -561,7 +561,7 @@ log_graph_fill(Application_Links *app, Rect_f32 layout_region, Face_ID face_id){ } if (emit_next_bucket){ - Log_Graph_Thread_Bucket *bucket = push_array(&log_arena, Log_Graph_Thread_Bucket, 1); + Log_Graph_Thread_Bucket *bucket = push_array(log_arena, Log_Graph_Thread_Bucket, 1); sll_queue_push(log_graph.first_bucket, log_graph.last_bucket, bucket); log_graph.bucket_count += 1; bucket->range.first = i; @@ -612,7 +612,7 @@ log_graph_fill(Application_Links *app, Rect_f32 layout_region, Face_ID face_id){ bucket_with_next_event->range.first += 1; - Log_Graph_Box *box_node = push_array(&log_arena, Log_Graph_Box, 1); + Log_Graph_Box *box_node = push_array(log_arena, Log_Graph_Box, 1); sll_queue_push(log_graph.first_box, log_graph.last_box, box_node); log_graph.box_count += 1; Rect_f32 rect = Rf32(box_w*bucket_with_next_event_index , y_cursor, @@ -632,17 +632,17 @@ log_graph_fill(Application_Links *app, Rect_f32 layout_region, Face_ID face_id){ internal void log_parse_fill(Application_Links *app, Buffer_ID buffer){ - if (log_arena.base_allocator == 0){ - log_arena = make_arena_app_links(app); + if (log_arena == 0){ + log_arena = reserve_arena(app); } - linalloc_clear(&log_arena); + linalloc_clear(log_arena); block_zero_struct(&log_graph); log_filter_set_init(&log_filter_set); log_filter_set_init(&log_preview_set); - String_Const_u8 log_text = push_whole_buffer(app, &log_arena, buffer); - log_parse = make_log_parse(&log_arena, log_text); + String_Const_u8 log_text = push_whole_buffer(app, log_arena, buffer); + log_parse = make_log_parse(log_arena, log_text); } internal void diff --git a/4coder_project_commands.cpp b/4coder_project_commands.cpp index d87571f9..99852250 100644 --- a/4coder_project_commands.cpp +++ b/4coder_project_commands.cpp @@ -5,7 +5,7 @@ // TOP static Project current_project = {}; -static Arena current_project_arena = {}; +static Arena *current_project_arena = {}; /////////////////////////////// @@ -707,13 +707,13 @@ set_current_project(Application_Links *app, Project *project, Config *parsed){ Scratch_Block scratch(app); if (parsed != 0 && project != 0){ - if (current_project_arena.base_allocator == 0){ - current_project_arena = make_arena_app_links(app, KB(64)); + if (current_project_arena == 0){ + current_project_arena = reserve_arena(app); } // Copy project to current_project - linalloc_clear(¤t_project_arena); - Project new_project = project_deep_copy(¤t_project_arena, project); + linalloc_clear(current_project_arena); + Project new_project = project_deep_copy(current_project_arena, project); if (new_project.loaded){ current_project = new_project; @@ -803,20 +803,16 @@ set_current_project(Application_Links *app, Project *project, Config *parsed){ static void set_current_project_from_data(Application_Links *app, String_Const_u8 file_name, Data data, String_Const_u8 file_dir){ - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app, Scratch_Share); Project_Parse_Result project_parse = parse_project__data(scratch, file_name, data, file_dir); set_current_project(app, project_parse.project, project_parse.parsed); - end_temp(temp); } static void set_current_project_from_nearest_project_file(Application_Links *app){ - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app, Scratch_Share); Project_Parse_Result project_parse = parse_project__nearest_file(app, scratch); set_current_project(app, project_parse.project, project_parse.parsed); - end_temp(temp); } static void @@ -1200,8 +1196,7 @@ project_generate_project_4coder_file(Arena *scratch, String_Const_u8 script_path static void project_setup_scripts__generic(Application_Links *app, b32 do_project_file, b32 do_bat_script, b32 do_sh_script){ - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(app); String_Const_u8 script_path = push_hot_directory(app, scratch); b32 needs_to_do_work = false; @@ -1299,8 +1294,6 @@ project_setup_scripts__generic(Application_Links *app, b32 do_project_file, b32 print_message(app, string_u8_litexpr("project already setup, no changes made\n")); } } - - end_temp(temp); } CUSTOM_COMMAND_SIG(setup_new_project) @@ -1341,11 +1334,10 @@ CUSTOM_COMMAND_SIG(project_command_lister) CUSTOM_DOC("Open a lister of all commands in the currently loaded project.") { if (current_project.loaded){ - Arena *scratch = context_get_arena(app); + Scratch_Block scratch(app, Scratch_Share); View_ID view = get_active_view(app, AccessAll); view_end_ui_mode(app, view); - Temp_Memory temp = begin_temp(scratch); i32 option_count = current_project.command_array.count; Lister_Option *options = push_array(scratch, Lister_Option, option_count); for (i32 i = 0; @@ -1356,7 +1348,6 @@ CUSTOM_DOC("Open a lister of all commands in the currently loaded project.") options[i].user_data = IntAsPtr(i); } begin_integrated_lister__basic_list(app, "Command:", activate_project_command, 0, 0, options, option_count, 0, view); - end_temp(temp); } } diff --git a/4coder_remapping_commands.cpp b/4coder_remapping_commands.cpp index 3bb9aaed..d80dc9d5 100644 --- a/4coder_remapping_commands.cpp +++ b/4coder_remapping_commands.cpp @@ -51,31 +51,23 @@ CUSTOM_DOC("Remap keybindings using the 'choose' mapping rule.") CUSTOM_COMMAND_SIG(set_bindings_default) CUSTOM_DOC("Remap keybindings using the 'default' mapping rule.") { - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); - + Scratch_Block scratch(app, Scratch_Share); Bind_Helper context = get_context_on_arena(scratch); set_all_default_hooks(&context); default_keys(&context); Bind_Buffer result = end_bind_helper_get_buffer(&context); global_set_mapping(app, result.data, result.size); - - end_temp(temp); } CUSTOM_COMMAND_SIG(set_bindings_mac_default) CUSTOM_DOC("Remap keybindings using the 'mac-default' mapping rule.") { - Arena *scratch = context_get_arena(app); - Temp_Memory temp = begin_temp(scratch); - + Scratch_Block scratch(app, Scratch_Share); Bind_Helper context = get_context_on_arena(scratch); set_all_default_hooks(&context); mac_default_keys(&context); Bind_Buffer result = end_bind_helper_get_buffer(&context); global_set_mapping(app, result.data, result.size); - - end_temp(temp); } #endif diff --git a/4coder_search.cpp b/4coder_search.cpp index 009bf7db..4c8d1361 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -252,7 +252,8 @@ string_match_list_enclose_all(Application_Links *app, String_Match_List list, En internal List_String_Const_u8 string_match_list_deduplicated_strings(Application_Links *app, Arena *arena, String_Match_List list){ List_String_Const_u8 extension_list = {}; - Table_Data_u64 table = make_table_Data_u64(context_get_base_allocator(app), 128); + Thread_Context *tctx = get_thread_context(app); + Table_Data_u64 table = make_table_Data_u64(tctx->allocator, 128); for (String_Match *node = list.first; node != 0; node = node->next){ @@ -272,8 +273,9 @@ string_match_list_deduplicated_strings(Application_Links *app, Arena *arena, Str internal void string_match_list_deduplicate(Application_Links *app, String_Match_List *list){ String_Match_List new_list = {}; - Scratch_Block scratch(app); - Table_Data_u64 table = make_table_Data_u64(context_get_base_allocator(app), 128); + Thread_Context *tctx = get_thread_context(app); + Scratch_Block scratch(tctx); + Table_Data_u64 table = make_table_Data_u64(tctx->allocator, 128); for (String_Match *node = list->first, *next = 0; node != 0; node = next){ @@ -388,20 +390,20 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with } *rewrite = Rewrite_WordComplete; - local_persist Arena completion_arena = {}; - if (completion_arena.base_allocator == 0){ - completion_arena = make_arena_app_links(app); + local_persist Arena *completion_arena = {}; + if (completion_arena == 0){ + completion_arena = reserve_arena(app); } local_persist Word_Complete_State state = {}; if (first_completion || !state.initialized){ block_zero_struct(&state); - linalloc_clear(&completion_arena); + linalloc_clear(completion_arena); i64 pos = view_get_cursor_pos(app, view); Range_i64 needle_range = get_word_complete_needle_range(app, buffer, pos); if (range_size(needle_range) > 0){ - state = get_word_complete_state(app, &completion_arena, buffer, needle_range); + state = get_word_complete_state(app, completion_arena, buffer, needle_range); } } diff --git a/4coder_ui_helper.cpp b/4coder_ui_helper.cpp index 49b2e725..f6841db4 100644 --- a/4coder_ui_helper.cpp +++ b/4coder_ui_helper.cpp @@ -292,8 +292,7 @@ lister_update_ui(Application_Links *app, View_ID view, Lister_State *state){ f32 block_height = lister_get_block_height(line_height, is_theme_list); f32 text_field_height = lister_get_text_field_height(metrics.line_height); - Arena *scratch = context_get_arena(app); - Temp_Memory full_temp = begin_temp(scratch); + Scratch_Block scratch(app, Scratch_Share); Rect_f32 region = view_get_buffer_region(app, view); Vec2_f32 view_m = get_mouse_position_in_panel_space(app, region.p0); @@ -481,8 +480,6 @@ lister_update_ui(Application_Links *app, View_ID view, Lister_State *state){ //UI_Control control = ui_list_to_ui_control(scratch, &list); view_set_quit_ui_handler(app, view, lister_quit_function); } - - end_temp(full_temp); } static Lister_Prealloced_String @@ -494,19 +491,18 @@ lister_prealloced(String_Const_u8 string){ static void lister_first_init(Application_Links *app, Lister *lister, void *user_data, i32 user_data_size){ - if (lister->arena.base_allocator == 0) { - lister->arena = make_arena_app_links(app, KB(16)); + if (lister->arena == 0) { + lister->arena = reserve_arena(app, KB(16)); } else{ - linalloc_clear(&lister->arena); + linalloc_clear(lister->arena); } block_zero_struct(&lister->data); lister->data.query = Su8(lister->data.query_space, 0, sizeof(lister->data.query_space)); lister->data.text_field = Su8(lister->data.text_field_space, 0, sizeof(lister->data.text_field_space)); lister->data.key_string = Su8(lister->data.key_string_space, 0, sizeof(lister->data.key_string_space)); - lister->data.user_data = push_array(&lister->arena, char, user_data_size); + lister->data.user_data = push_array(lister->arena, char, user_data_size); lister->data.user_data_size = user_data_size; - push_align(&lister->arena, 8); if (user_data != 0){ block_copy(lister->data.user_data, user_data, user_data_size); } @@ -514,14 +510,14 @@ lister_first_init(Application_Links *app, Lister *lister, void *user_data, i32 u static void lister_begin_new_item_set(Application_Links *app, Lister *lister){ - linalloc_clear(&lister->arena); + linalloc_clear(lister->arena); block_zero_struct(&lister->data.options); } static void* lister_add_item(Lister *lister, Lister_Prealloced_String string, Lister_Prealloced_String status, void *user_data, umem extra_space){ - void *base_memory = push_array(&lister->arena, u8, sizeof(Lister_Node) + extra_space); + void *base_memory = push_array(lister->arena, u8, sizeof(Lister_Node) + extra_space); Lister_Node *node = (Lister_Node*)base_memory; node->string = string.string; node->status = status.string; @@ -536,22 +532,22 @@ lister_add_item(Lister *lister, Lister_Prealloced_String string, Lister_Prealloc static void* lister_add_item(Lister *lister, Lister_Prealloced_String string, String_Const_u8 status, void *user_data, umem extra_space){ - return(lister_add_item(lister, string, lister_prealloced(push_string_copy(&lister->arena, status)), + return(lister_add_item(lister, string, lister_prealloced(push_string_copy(lister->arena, status)), user_data, extra_space)); } static void* lister_add_item(Lister *lister, String_Const_u8 string, Lister_Prealloced_String status, void *user_data, umem extra_space){ - return(lister_add_item(lister, lister_prealloced(push_string_copy(&lister->arena, string)), status, + return(lister_add_item(lister, lister_prealloced(push_string_copy(lister->arena, string)), status, user_data, extra_space)); } static void* lister_add_item(Lister *lister, String_Const_u8 string, String_Const_u8 status, void *user_data, umem extra_space){ return(lister_add_item(lister, - lister_prealloced(push_string_copy(&lister->arena, string)), - lister_prealloced(push_string_copy(&lister->arena, status)), + lister_prealloced(push_string_copy(lister->arena, string)), + lister_prealloced(push_string_copy(lister->arena, status)), user_data, extra_space)); } @@ -559,22 +555,22 @@ static void* lister_add_theme_item(Lister *lister, Lister_Prealloced_String string, i32 index, void *user_data, i32 extra_space){ - Lister_Node *node = push_array(&lister->arena, Lister_Node, 1); + Lister_Node *node = push_array(lister->arena, Lister_Node, 1); node->string = string.string; node->index = index; node->user_data = user_data; node->raw_index = lister->data.options.count; zdll_push_back(lister->data.options.first, lister->data.options.last, node); lister->data.options.count += 1; - void *result = push_array(&lister->arena, char, extra_space); - push_align(&lister->arena, 8); + void *result = push_array(lister->arena, char, extra_space); + push_align(lister->arena, 8); return(result); } static void* lister_add_theme_item(Lister *lister, String_Const_u8 string, i32 index, void *user_data, i32 extra_space){ - return(lister_add_theme_item(lister, lister_prealloced(push_string_copy(&lister->arena, string)), index, + return(lister_add_theme_item(lister, lister_prealloced(push_string_copy(lister->arena, string)), index, user_data, extra_space)); } @@ -609,7 +605,7 @@ lister_default(Application_Links *app, Heap *heap, View_ID view, Lister_State *s { view_end_ui_mode(app, view); state->initialized = false; - linalloc_clear(&state->lister.arena); + linalloc_clear(state->lister.arena); }break; case ListerActivation_Continue: diff --git a/4coder_ui_helper.h b/4coder_ui_helper.h index e93da4d3..68022783 100644 --- a/4coder_ui_helper.h +++ b/4coder_ui_helper.h @@ -115,7 +115,7 @@ struct Lister_Data{ }; struct Lister{ - Arena arena; + Arena *arena; Lister_Data data; }; diff --git a/4ed.cpp b/4ed.cpp index 5a007727..0a40f045 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -161,9 +161,8 @@ internal b32 interpret_binding_buffer(Models *models, void *buffer, i32 size){ b32 result = true; - Heap *gen = &models->mem.heap; - Arena *scratch = &models->mem.arena; - Temp_Memory temp = begin_temp(scratch); + Heap *gen = &models->heap; + Scratch_Block scratch(models->tctx, Scratch_Share); Mapping new_mapping = {}; @@ -454,7 +453,6 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){ } models->mapping = new_mapping; - end_temp(temp); return(result); } @@ -476,9 +474,7 @@ command_caller(Coroutine *coroutine){ } internal void -app_links_init(System_Functions *system, Application_Links *app_links, void *data, i32 size){ - app_links->memory = data; - app_links->memory_size = size; +app_links_init(System_Functions *system, Application_Links *app_links){ FillAppLinksAPI(app_links); app_links->current_coroutine = 0; app_links->system_links = system; @@ -539,10 +535,9 @@ fill_hardcode_default_style(Color_Table color_table){ internal void app_hardcode_default_style(Models *models){ - Arena *arena = &models->mem.arena; Color_Table color_table = {}; color_table.count = Stag_COUNT; - color_table.vals = push_array(arena, u32, color_table.count); + color_table.vals = push_array(models->arena, u32, color_table.count); fill_hardcode_default_style(color_table); models->fallback_color_table = color_table; } @@ -718,12 +713,12 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, //////////////////////////////// internal Models* -app_setup_memory(System_Functions *system, Application_Memory *memory){ - Cursor cursor = make_cursor(memory->vars_memory, memory->vars_memory_size); - Models *models = push_array_zero(&cursor, Models, 1); - models->mem.arena = make_arena_system(system); - models->base_allocator = models->mem.arena.base_allocator; - heap_init(&models->mem.heap, models->base_allocator); +models_init(Thread_Context *tctx){ + Arena *arena = reserve_arena(tctx); + Models *models = push_array_zero(arena, Models, 1); + models->tctx = tctx; + models->arena = arena; + heap_init(&models->heap, tctx->allocator); return(models); } @@ -811,8 +806,8 @@ app_get_logger(System_Functions *system){ } App_Read_Command_Line_Sig(app_read_command_line){ - i32 out_size = 0; - Models *models = app_setup_memory(system, memory); + Models *models = models_init(tctx); + models->system = system; App_Settings *settings = &models->settings; block_zero_struct(settings); if (argc > 1){ @@ -820,21 +815,19 @@ App_Read_Command_Line_Sig(app_read_command_line){ } *files = models->settings.init_files; *file_count = &models->settings.init_files_count; - return(out_size); + return(models); } App_Init_Sig(app_init){ - Models *models = (Models*)memory->vars_memory; - models->system = system; + Models *models = (Models*)base_ptr; models->keep_playing = true; - app_links_init(system, &models->app_links, memory->user_memory, memory->user_memory_size); - models->custom_layer_arena = make_arena_models(models); + app_links_init(system, &models->app_links); models->config_api = api; models->app_links.cmd_context = models; - Arena *arena = &models->mem.arena; + Arena *arena = models->arena; // NOTE(allen): coroutines coroutine_system_init(system, &models->coroutines); @@ -865,14 +858,15 @@ App_Init_Sig(app_init){ { Assert(models->config_api.get_bindings != 0); - i32 wanted_size = models->config_api.get_bindings(models->app_links.memory, models->app_links.memory_size); - Assert(wanted_size <= models->app_links.memory_size); - interpret_binding_buffer(models, models->app_links.memory, wanted_size); - memset(models->app_links.memory, 0, wanted_size); + Scratch_Block scratch(models->tctx); + u8 *memory = push_array(scratch, u8, KB(64)); + i32 wanted_size = models->config_api.get_bindings(memory, KB(64)); + Assert(wanted_size <= KB(64)); + interpret_binding_buffer(models, memory, wanted_size); } - managed_ids_init(models->base_allocator, &models->managed_id_set); - lifetime_allocator_init(models->base_allocator, &models->lifetime_allocator); + managed_ids_init(models->tctx->allocator, &models->managed_id_set); + lifetime_allocator_init(models->tctx->allocator, &models->lifetime_allocator); dynamic_workspace_init(&models->lifetime_allocator, DynamicWorkspace_Global, 0, &models->dynamic_workspace); // NOTE(allen): file setup @@ -892,7 +886,7 @@ App_Init_Sig(app_init){ // TODO(allen): do(better clipboard allocation) if (clipboard.str != 0){ - String_Const_u8 *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size); + String_Const_u8 *dest = working_set_next_clipboard_string(&models->heap, &models->working_set, clipboard.size); block_copy(dest->str, clipboard.str, clipboard.size); } @@ -920,7 +914,7 @@ App_Init_Sig(app_init){ { string_u8_litinit("*log*") , &models->log_buffer , true , }, }; - Heap *heap = &models->mem.heap; + Heap *heap = &models->heap; for (i32 i = 0; i < ArrayCount(init_files); ++i){ Editing_File *file = working_set_allocate_file(&models->working_set, &models->lifetime_allocator); buffer_bind_name(models, arena, &models->working_set, file, init_files[i].name); @@ -933,7 +927,7 @@ App_Init_Sig(app_init){ file_create_from_string(models, file, SCu8(), attributes); if (init_files[i].read_only){ file->settings.read_only = true; - history_free(&file->state.history); + history_free(models, &file->state.history); } file->settings.never_kill = true; @@ -949,14 +943,14 @@ App_Init_Sig(app_init){ // NOTE(allen): miscellaneous init hot_directory_init(system, arena, &models->hot_directory, current_directory); - child_process_container_init(models->base_allocator, &models->child_processes); + child_process_container_init(models->tctx->allocator, &models->child_processes); models->user_up_key = key_up; models->user_down_key = key_down; models->period_wakeup_timer = system->wake_up_timer_create(); } App_Step_Sig(app_step){ - Models *models = (Models*)memory->vars_memory; + Models *models = (Models*)base_ptr; Mutex_Lock file_order_lock(system, models->working_set.mutex); @@ -971,7 +965,7 @@ App_Step_Sig(app_step){ // NOTE(allen): OS clipboard event handling String_Const_u8 clipboard = input->clipboard; if (clipboard.str != 0){ - String_Const_u8 *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size); + String_Const_u8 *dest = working_set_next_clipboard_string(&models->heap, &models->working_set, clipboard.size); dest->size = eol_convert_in((char*)dest->str, (char*)clipboard.str, (i32)clipboard.size); if (input->clipboard_changed && models->clipboard_change != 0){ models->clipboard_change(&models->app_links, *dest, ClipboardFlag_FromOS); @@ -986,10 +980,9 @@ App_Step_Sig(app_step){ // NOTE(allen): update child processes f32 dt = input->dt; if (dt > 0){ - Arena *scratch = &models->mem.arena; + Scratch_Block scratch(models->tctx, Scratch_Share); Child_Process_Container *child_processes = &models->child_processes; - Temp_Memory temp = begin_temp(scratch); Child_Process **processes_to_free = push_array(scratch, Child_Process*, child_processes->active_child_process_count); i32 processes_to_free_count = 0; @@ -1035,8 +1028,6 @@ App_Step_Sig(app_step){ for (i32 i = 0; i < processes_to_free_count; ++i){ child_process_free(child_processes, processes_to_free[i]->id); } - - end_temp(temp); } // NOTE(allen): input filter and simulated events diff --git a/4ed.h b/4ed.h index be88592d..608c7b92 100644 --- a/4ed.h +++ b/4ed.h @@ -14,18 +14,6 @@ #define MAX_VIEWS 16 -// TODO(allen): This is DONE! GET RID OF IT NAO! -struct Application_Memory{ - void *vars_memory; - i32 vars_memory_size; - void *target_memory; - i32 target_memory_size; - void *user_memory; - i32 user_memory_size; - void *debug_memory; - i32 debug_memory_size; -}; - // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen): @@ -68,7 +56,7 @@ struct Plat_Settings{ }; #define App_Read_Command_Line_Sig(name) \ -i32 name(System_Functions *system, Application_Memory *memory, String_Const_u8 current_directory, Plat_Settings *plat_settings, char ***files, i32 **file_count, i32 argc, char **argv) +void *name(Thread_Context *tctx, System_Functions *system, String_Const_u8 current_directory, Plat_Settings *plat_settings, char ***files, i32 **file_count, i32 argc, char **argv) typedef App_Read_Command_Line_Sig(App_Read_Command_Line); @@ -78,7 +66,7 @@ struct Custom_API{ }; #define App_Init_Sig(name) \ -void name(System_Functions *system, Render_Target *target, Application_Memory *memory, String_Const_u8 clipboard, String_Const_u8 current_directory, Custom_API api) +void name(System_Functions *system, Render_Target *target, void *base_ptr, String_Const_u8 clipboard, String_Const_u8 current_directory, Custom_API api) typedef App_Init_Sig(App_Init); @@ -106,7 +94,7 @@ struct Application_Step_Input{ #define App_Step_Sig(name) Application_Step_Result \ name(System_Functions *system, \ Render_Target *target, \ -Application_Memory *memory, \ +void *base_ptr, \ Application_Step_Input *input) typedef App_Step_Sig(App_Step); diff --git a/4ed_allocator_models.cpp b/4ed_allocator_models.cpp index 74237141..fe74d240 100644 --- a/4ed_allocator_models.cpp +++ b/4ed_allocator_models.cpp @@ -9,19 +9,28 @@ // TOP -internal Arena -make_arena_models(Models *models, umem chunk_size, umem align){ - return(make_arena(models->base_allocator, chunk_size, align)); +internal Arena* +reserve_arena(Models *models, umem chunk_size, umem align){ + Thread_Context *tctx = models->tctx; + return(reserve_arena(tctx, chunk_size, align)); } -internal Arena -make_arena_models(Models *models, umem chunk_size){ - return(make_arena(models->base_allocator, chunk_size, 8)); +internal Arena* +reserve_arena(Models *models, umem chunk_size){ + Thread_Context *tctx = models->tctx; + return(reserve_arena(tctx, chunk_size)); } -internal Arena -make_arena_models(Models *models){ - return(make_arena(models->base_allocator, KB(16), 8)); +internal Arena* +reserve_arena(Models *models){ + Thread_Context *tctx = models->tctx; + return(reserve_arena(tctx)); +} + +internal void +release_arena(Models *models, Arena *arena){ + Thread_Context *tctx = models->tctx; + release_arena(tctx, arena); } // BOTTOM diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index e31d2812..3c9d8629 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -80,16 +80,10 @@ Global_Get_Screen_Rectangle(Application_Links *app){ return(Rf32(V2(0, 0), V2(layout_get_root_size(&models->layout)))); } -API_EXPORT Arena* -Context_Get_Arena(Application_Links *app){ +API_EXPORT Thread_Context* +Get_Thread_Context(Application_Links *app){ Models *models = (Models*)app->cmd_context; - return(&models->custom_layer_arena); -} - -API_EXPORT Base_Allocator* -Context_Get_Base_Allocator(Application_Links *app){ - Models *models = (Models*)app->cmd_context; - return(models->base_allocator); + return(models->tctx); } API_EXPORT b32 @@ -143,7 +137,7 @@ API_EXPORT b32 Clipboard_Post(Application_Links *app, i32 clipboard_id, String_Const_u8 string) { Models *models = (Models*)app->cmd_context; - String_Const_u8 *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, (i32)string.size); + String_Const_u8 *dest = working_set_next_clipboard_string(&models->heap, &models->working_set, (i32)string.size); block_copy(dest->str, string.str, string.size); models->system->post_clipboard(*dest); return(true); @@ -760,12 +754,12 @@ Buffer_Set_Setting(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_I { if (value){ if (!history_is_activated(&file->state.history)){ - history_init(app, &file->state.history); + history_init(models, &file->state.history); } } else{ if (history_is_activated(&file->state.history)){ - history_free(&file->state.history); + history_free(models, &file->state.history); } } }break; @@ -834,11 +828,9 @@ Buffer_Save(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_na } if (!skip_save){ - Arena *scratch = &models->mem.arena; - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(models->tctx, Scratch_Share); String_Const_u8 name = push_string_copy(scratch, file_name); save_file_to_name(system, models, file, name.str); - end_temp(temp); result = true; } } @@ -866,8 +858,8 @@ Buffer_Kill(Application_Links *app, Buffer_ID buffer_id, Buffer_Kill_Flag flags) if (file->canon.name_size != 0){ buffer_unbind_file(system, working_set, file); } - file_free(system, &models->lifetime_allocator, working_set, file); - working_set_free_file(&models->mem.heap, working_set, file); + file_free(models, file); + working_set_free_file(&models->heap, working_set, file); Layout *layout = &models->layout; @@ -908,17 +900,16 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl { Models *models = (Models*)app->cmd_context; System_Functions *system = models->system; - Arena *arena = &models->mem.arena; + Scratch_Block scratch(models->tctx, Scratch_Share); Editing_File *file = imp_get_file(models, buffer_id); Buffer_Reopen_Result result = BufferReopenResult_Failed; if (api_check_buffer(file)){ if (file->canon.name_size > 0){ Plat_Handle handle = {}; - if (system->load_handle(arena, (char*)file->canon.name_space, &handle)){ + if (system->load_handle(scratch, (char*)file->canon.name_space, &handle)){ File_Attributes attributes = system->load_attributes(handle); - Temp_Memory temp = begin_temp(arena); - char *file_memory = push_array(arena, char, (i32)attributes.size); + char *file_memory = push_array(scratch, char, (i32)attributes.size); if (file_memory != 0){ if (system->load_file(handle, file_memory, (i32)attributes.size)){ @@ -948,7 +939,7 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl } Working_Set *working_set = &models->working_set; - file_free(system, &models->lifetime_allocator, working_set, file); + file_free(models, file); working_set_file_default_settings(working_set, file); file_create_from_string(models, file, SCu8(file_memory, attributes.size), attributes); @@ -970,8 +961,6 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl else{ system->load_close(handle); } - - end_temp(temp); } } } @@ -994,8 +983,8 @@ API_EXPORT File_Attributes Get_File_Attributes(Application_Links *app, String_Const_u8 file_name) { Models *models = (Models*)app->cmd_context; - Arena *arena = &models->mem.arena; - return(models->system->quick_file_attributes(arena, file_name)); + Scratch_Block scratch(models->tctx, Scratch_Share); + return(models->system->quick_file_attributes(scratch, file_name)); } internal View* @@ -1813,9 +1802,8 @@ Get_Managed_Scope_With_Multiple_Dependencies(Application_Links *app, Managed_Sco { Models *models = (Models*)app->cmd_context; Lifetime_Allocator *lifetime_allocator = &models->lifetime_allocator; - Arena *scratch = &models->mem.arena; - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(models->tctx, Scratch_Share); // TODO(allen): revisit this struct Node_Ptr{ @@ -1890,8 +1878,6 @@ Get_Managed_Scope_With_Multiple_Dependencies(Application_Links *app, Managed_Sco result = (Managed_Scope)key->dynamic_workspace.scope_id; } - end_temp(temp); - return(result); } @@ -2843,7 +2829,7 @@ Text_Layout_Create(Application_Links *app, Buffer_ID buffer_id, Rect_f32 rect, B Text_Layout_ID result = {}; if (api_check_buffer(file)){ Scratch_Block scratch(app); - Arena arena = make_arena_models(models); + Arena *arena = reserve_arena(models->tctx); Face *face = file_get_face(models, file); Gap_Buffer *buffer = &file->state.buffer; @@ -2868,7 +2854,7 @@ Text_Layout_Create(Application_Links *app, Buffer_ID buffer_id, Rect_f32 rect, B buffer_get_last_pos_from_line_number(buffer, visible_line_number_range.max)); i64 item_count = range_size_inclusive(visible_range); - int_color *colors_array = push_array(&arena, int_color, item_count); + int_color *colors_array = push_array(arena, int_color, item_count); for (i64 i = 0; i < item_count; i += 1){ colors_array[i] = Stag_Default; } @@ -3018,7 +3004,7 @@ Paint_Text_Color(Application_Links *app, Text_Layout_ID layout_id, Interval_i64 API_EXPORT b32 Text_Layout_Free(Application_Links *app, Text_Layout_ID text_layout_id){ Models *models = (Models*)app->cmd_context; - return(text_layout_erase(&models->text_layouts, text_layout_id)); + return(text_layout_erase(models, &models->text_layouts, text_layout_id)); } API_EXPORT void diff --git a/4ed_app_models.h b/4ed_app_models.h index f3da21b3..373fcd60 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -36,8 +36,10 @@ enum App_State{ struct Models{ System_Functions *system; - Base_Allocator *base_allocator; - Mem_Options mem; + Thread_Context *tctx; + + Arena *arena; + Heap heap; App_Settings settings; App_State state; @@ -114,8 +116,6 @@ struct Models{ u32 next_animate_delay; b32 animate_next_frame; - Arena custom_layer_arena; - // Last frame state Vec2_i32 prev_p; Panel *prev_mouse_panel; diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index 99c84469..d4734180 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -32,12 +32,6 @@ #include "4coder_lib/4coder_utf8.h" -// TODO(allen): stop this nonsense -struct Mem_Options{ - Arena arena; - Heap heap; -}; - #include "4ed_render_target.h" #include "4ed.h" #include "4ed_buffer_model.h" diff --git a/4ed_buffer.cpp b/4ed_buffer.cpp index fb9e61f4..12b2e101 100644 --- a/4ed_buffer.cpp +++ b/4ed_buffer.cpp @@ -694,8 +694,8 @@ buffer_layout__write(Arena *arena, Buffer_Layout_Item_List *list, i64 index, u32 } internal Buffer_Layout_Item_List -buffer_layout(Arena *scratch, Arena *arena, Gap_Buffer *buffer, Interval_i64 range, Face *face, f32 width){ - Temp_Memory temp = begin_temp(scratch); +buffer_layout(Thread_Context *tctx, Arena *arena, Gap_Buffer *buffer, Interval_i64 range, Face *face, f32 width){ + Scratch_Block scratch(tctx); Buffer_Layout_Item_List list = {}; list.index_range.first = range.first; @@ -822,8 +822,6 @@ buffer_layout(Arena *scratch, Arena *arena, Gap_Buffer *buffer, Interval_i64 ran } } - end_temp(temp); - return(list); } diff --git a/4ed_dynamic_variables.cpp b/4ed_dynamic_variables.cpp index d177048d..5dad2e76 100644 --- a/4ed_dynamic_variables.cpp +++ b/4ed_dynamic_variables.cpp @@ -99,7 +99,8 @@ dynamic_workspace_free(Lifetime_Allocator *lifetime_allocator, Dynamic_Workspace internal void dynamic_workspace_clear_contents(Dynamic_Workspace *workspace){ - Base_Allocator *base_allocator = heap_free_all(&workspace->heap); + Base_Allocator *base_allocator = heap_get_base_allocator(&workspace->heap); + heap_free_all(&workspace->heap); heap_init(&workspace->heap, base_allocator); workspace->heap_wrapper = base_allocator_on_heap(&workspace->heap); workspace->object_id_to_object_ptr = make_table_u64_u64(&workspace->heap_wrapper, 10); diff --git a/4ed_edit.cpp b/4ed_edit.cpp index 9ddf64a1..2b0d5a1a 100644 --- a/4ed_edit.cpp +++ b/4ed_edit.cpp @@ -98,8 +98,8 @@ edit_fix_markers(Models *models, Editing_File *file, Edit edit){ } cursor_max += total_marker_count; - Arena *scratch = &models->mem.arena; - Temp_Memory cursor_temp = begin_temp(scratch); + Scratch_Block scratch(models->tctx, Scratch_Share); + Cursor_With_Index *cursors = push_array(scratch, Cursor_With_Index, cursor_max); Cursor_With_Index *r_cursors = push_array(scratch, Cursor_With_Index, cursor_max); i32 cursor_count = 0; @@ -174,8 +174,6 @@ edit_fix_markers(Models *models, Editing_File *file, Edit edit){ key_index += count; } } - - end_temp(cursor_temp); } internal void @@ -189,8 +187,7 @@ edit_single(Models *models, Editing_File *file, Interval_i64 range, String_Const Assert(edit.range.first <= edit.range.one_past_last); Assert(edit.range.one_past_last <= buffer_size(buffer)); - Arena *scratch = &models->mem.arena; - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(models->tctx, Scratch_Share); // NOTE(allen): history update if (!behaviors.do_not_post_to_history){ @@ -232,8 +229,6 @@ edit_single(Models *models, Editing_File *file, Interval_i64 range, String_Const Interval_i64 new_range = Ii64(edit.range.first, edit.range.first + edit.text.size); models->hook_file_edit_range(&models->app_links, file->id, new_range, original_text); } - - end_temp(temp); } internal void @@ -375,7 +370,8 @@ edit_merge_history_range(Models *models, Editing_File *file, History_Record_Inde }break; } } - history_merge_records(&models->mem.arena, history, first_index, last_index); + Scratch_Block scratch(models->tctx, Scratch_Share); + history_merge_records(scratch, history, first_index, last_index); if (current_index >= last_index){ current_index -= (last_index - first_index); } @@ -437,10 +433,9 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags) if (file_name.size > 0){ System_Functions *system = models->system; Working_Set *working_set = &models->working_set; - Heap *heap = &models->mem.heap; + Heap *heap = &models->heap; - Arena *scratch = &models->mem.arena; - Temp_Memory temp = begin_temp(scratch); + Scratch_Block scratch(models->tctx); Editing_File *file = 0; b32 do_empty_buffer = false; @@ -555,8 +550,6 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags) models->hook_new_file != 0){ models->hook_new_file(&models->app_links, file->id); } - - end_temp(temp); } return(result); diff --git a/4ed_file.cpp b/4ed_file.cpp index 30c7ff71..9f0568f1 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -148,7 +148,6 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, } if (file_name != 0){ - Mem_Options *mem = &models->mem; if (models->hook_save_file != 0){ models->hook_save_file(&models->app_links, file->id); } @@ -156,7 +155,8 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, Gap_Buffer *buffer = &file->state.buffer; b32 dos_write_mode = file->settings.dos_write_mode; - Arena *scratch = &mem->arena; + Scratch_Block scratch(models->tctx, Scratch_Share); + if (!using_actual_file_name){ String_Const_u8 s_file_name = SCu8(file_name); String_Const_u8 canonical_file_name = system->get_canonical(scratch, s_file_name); @@ -165,7 +165,6 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, } } - Temp_Memory temp = begin_temp(scratch); String_Const_u8 saveable_string = buffer_stringify(scratch, buffer, Ii64(0, buffer_size(buffer))); File_Attributes new_attributes = system->save_file(scratch, (char*)file_name, saveable_string); @@ -179,7 +178,6 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, "save file [last_write_time=0x%llx]", new_attributes.last_write_time); file_clear_dirty_flags(file); - end_temp(temp); } return(result); @@ -213,10 +211,10 @@ file_compute_cursor(Editing_File *file, Buffer_Seek seek){ internal void file_create_from_string(Models *models, Editing_File *file, String_Const_u8 val, File_Attributes attributes){ System_Functions *system = models->system; - Arena *scratch = &models->mem.arena; - Application_Links *app_links = &models->app_links; - Base_Allocator *allocator = models->base_allocator; + Thread_Context *tctx = models->tctx; + Scratch_Block scratch(tctx, Scratch_Share); + Base_Allocator *allocator = tctx->allocator; block_zero_struct(&file->state); buffer_init(&file->state.buffer, val.str, val.size, allocator); @@ -231,7 +229,7 @@ file_create_from_string(Models *models, Editing_File *file, String_Const_u8 val, buffer_measure_starts(scratch, &file->state.buffer); file->lifetime_object = lifetime_alloc_object(&models->lifetime_allocator, DynamicWorkspace_Buffer, file); - history_init(&models->app_links, &file->state.history); + history_init(models, &file->state.history); file->state.cached_layouts_arena = make_arena(allocator); file->state.line_layout_table = make_table_Data_u64(allocator, 500); @@ -252,12 +250,15 @@ file_create_from_string(Models *models, Editing_File *file, String_Const_u8 val, Buffer_Hook_Function *hook_open_file = models->hook_open_file; if (hook_open_file != 0){ - hook_open_file(app_links, file->id); + hook_open_file(&models->app_links, file->id); } } internal void -file_free(System_Functions *system, Lifetime_Allocator *lifetime_allocator, Working_Set *working_set, Editing_File *file){ +file_free(Models *models, Editing_File *file){ + Lifetime_Allocator *lifetime_allocator = &models->lifetime_allocator; + Working_Set *working_set = &models->working_set; + lifetime_free_object(lifetime_allocator, file->lifetime_object); Gap_Buffer *buffer = &file->state.buffer; @@ -266,7 +267,7 @@ file_free(System_Functions *system, Lifetime_Allocator *lifetime_allocator, Work base_free(buffer->allocator, buffer->line_starts); } - history_free(&file->state.history); + history_free(models, &file->state.history); linalloc_clear(&file->state.cached_layouts_arena); table_free(&file->state.line_layout_table); @@ -316,7 +317,7 @@ file_get_line_layout(Models *models, Editing_File *file, f32 width, Face *face, else{ list = push_array(&file->state.cached_layouts_arena, Buffer_Layout_Item_List, 1); Interval_i64 line_range = buffer_get_pos_range_from_line_number(&file->state.buffer, line_number); - *list = buffer_layout(&models->mem.arena, &file->state.cached_layouts_arena, + *list = buffer_layout(models->tctx, &file->state.cached_layouts_arena, &file->state.buffer, line_range, face, width); key_data = push_data_copy(&file->state.cached_layouts_arena, key_data); table_insert(&file->state.line_layout_table, key_data, (u64)PtrAsInt(list)); diff --git a/4ed_history.cpp b/4ed_history.cpp index a5eba5e8..1cceeaf4 100644 --- a/4ed_history.cpp +++ b/4ed_history.cpp @@ -129,10 +129,11 @@ global_history_adjust_edit_grouping_counter(Global_History *global_history, i32 } internal void -history_init(Application_Links *app, History *history){ +history_init(Models *models, History *history){ history->activated = true; - history->arena = make_arena_app_links(app, KB(32)); - heap_init(&history->heap, history->arena.base_allocator); + Thread_Context *tctx = models->tctx; + history->arena = reserve_arena(tctx, KB(32)); + heap_init(&history->heap, tctx->allocator); history->heap_wrapper = base_allocator_on_heap(&history->heap); dll_init_sentinel(&history->free_records); dll_init_sentinel(&history->records); @@ -146,9 +147,9 @@ history_is_activated(History *history){ } internal void -history_free(History *history){ +history_free(Models *models, History *history){ if (history->activated){ - linalloc_clear(&history->arena); + release_arena(models, history->arena); heap_free_all(&history->heap); block_zero_struct(history); } @@ -248,13 +249,13 @@ history_record_edit(Global_History *global_history, History *history, Gap_Buffer Record *new_record = history__allocate_record(history); history__stash_record(history, new_record); - new_record->restore_point = begin_temp(&history->arena); + new_record->restore_point = begin_temp(history->arena); new_record->edit_number = global_history_get_edit_number(global_history); new_record->kind = RecordKind_Single; - new_record->single.forward_text = push_string_copy(&history->arena, edit.text); - new_record->single.backward_text = buffer_stringify(&history->arena, buffer, edit.range); + new_record->single.forward_text = push_string_copy(history->arena, edit.text); + new_record->single.backward_text = buffer_stringify(history->arena, buffer, edit.range); new_record->single.first = edit.range.first; Assert(history->record_lookup.count == history->record_count); @@ -340,8 +341,8 @@ history__optimize_group(Arena *scratch, History *history, Record *record){ end_temp(left->restore_point); left->edit_number = right->edit_number; - left->single.forward_text = push_string_copy(&history->arena, merged_forward); - left->single.backward_text = push_string_copy(&history->arena, merged_backward); + left->single.forward_text = push_string_copy(history->arena, merged_forward); + left->single.backward_text = push_string_copy(history->arena, merged_backward); history__free_single_node(history, &right->node); record->group.count -= 1; diff --git a/4ed_history.h b/4ed_history.h index 38f91765..0ef3624e 100644 --- a/4ed_history.h +++ b/4ed_history.h @@ -44,7 +44,7 @@ struct Record_Ptr_Lookup_Table{ struct History{ b32 activated; - Arena arena; + Arena *arena; Heap heap; Base_Allocator heap_wrapper; Node free_records; diff --git a/4ed_text_layout.cpp b/4ed_text_layout.cpp index 3f6b0f7b..1e72bd8b 100644 --- a/4ed_text_layout.cpp +++ b/4ed_text_layout.cpp @@ -12,15 +12,15 @@ internal void text_layout_init(Models *models, Text_Layout_Container *container){ block_zero_struct(container); - container->node_arena = make_arena_models(models); - container->table = make_table_u64_u64(models->base_allocator, 20); + container->node_arena = reserve_arena(models->tctx); + container->table = make_table_u64_u64(models->tctx->allocator, 20); } internal Text_Layout* text_layout_new__alloc_layout(Text_Layout_Container *container){ Text_Layout *node = container->free_nodes; if (node == 0){ - node = push_array(&container->node_arena, Text_Layout, 1); + node = push_array(container->node_arena, Text_Layout, 1); } else{ sll_stack_pop(container->free_nodes); @@ -29,13 +29,13 @@ text_layout_new__alloc_layout(Text_Layout_Container *container){ } internal void -text_layout_release(Text_Layout_Container *container, Text_Layout *layout){ - linalloc_clear(&layout->arena); +text_layout_release(Models *models, Text_Layout_Container *container, Text_Layout *layout){ + release_arena(models->tctx, layout->arena); sll_stack_push(container->free_nodes, layout); } internal Text_Layout_ID -text_layout_new(Text_Layout_Container *container, Arena arena, +text_layout_new(Text_Layout_Container *container, Arena *arena, Buffer_ID buffer_id, Buffer_Point point, Interval_i64 visible_range, Interval_i64 visible_line_number_range, Rect_f32 rect, int_color *item_colors){ @@ -65,14 +65,14 @@ text_layout_get(Text_Layout_Container *container, Text_Layout_ID id){ } internal b32 -text_layout_erase(Text_Layout_Container *container, Text_Layout_ID id){ +text_layout_erase(Models *models, Text_Layout_Container *container, Text_Layout_ID id){ b32 result = false; Table_Lookup lookup = table_lookup(&container->table, id); if (lookup.found_match){ u64 ptr_val = 0; table_read(&container->table, lookup, &ptr_val); Text_Layout *ptr = (Text_Layout*)IntAsPtr(ptr_val); - text_layout_release(container, ptr); + text_layout_release(models, container, ptr); table_erase(&container->table, lookup); result = true; } @@ -85,7 +85,6 @@ internal void text_layout_render(Models *models, Text_Layout *layout){ Editing_File *file = imp_get_file(models, layout->buffer_id); if (file != 0){ - Arena *scratch = &models->mem.arena; Render_Target *target = models->target; Color_Table color_table = models->color_table; Face *face = file_get_face(models, file); diff --git a/4ed_text_layout.h b/4ed_text_layout.h index 47d28f02..0befaff8 100644 --- a/4ed_text_layout.h +++ b/4ed_text_layout.h @@ -15,7 +15,7 @@ union Text_Layout{ Text_Layout *next; struct{ - Arena arena; + Arena *arena; Buffer_ID buffer_id; Buffer_Point point; Interval_i64 visible_range; @@ -26,7 +26,7 @@ union Text_Layout{ }; struct Text_Layout_Container{ - Arena node_arena; + Arena *node_arena; Text_Layout *free_nodes; Table_u64_u64 table; Text_Layout_ID id_counter; diff --git a/platform_all/4ed_shared_init_logic.cpp b/platform_all/4ed_shared_init_logic.cpp index 98a8d466..b82ee4b3 100644 --- a/platform_all/4ed_shared_init_logic.cpp +++ b/platform_all/4ed_shared_init_logic.cpp @@ -10,44 +10,10 @@ // TOP internal void -memory_init(Arena *scratch){ -#if defined(FRED_INTERNAL) -# if ARCH_64BIT - void *bases[] = { (void*)TB(1), (void*)TB(2), }; -# else - void *bases[] = { (void*)MB(96), (void*)MB(512), }; -# endif -#else - void *bases[] = { (void*)0, (void*)0, }; -#endif - - memory_vars.vars_memory_size = MB(128); - memory_vars.vars_memory = system_memory_allocate_extended(bases[0], memory_vars.vars_memory_size); - memory_vars.target_memory_size = MB(512); - memory_vars.target_memory = system_memory_allocate_extended(bases[1], memory_vars.target_memory_size); - memory_vars.user_memory_size = MB(32); - memory_vars.user_memory = system_memory_allocate_extended(0, memory_vars.user_memory_size); - memory_vars.debug_memory_size = MB(512); - memory_vars.debug_memory = system_memory_allocate_extended(0, memory_vars.debug_memory_size); - - i32 render_memsize = MB(1); - target.arena = make_arena_system(&sysfunc); - - b32 alloc_success = true; - if (memory_vars.vars_memory == 0 || memory_vars.target_memory == 0 || memory_vars.user_memory == 0){ - alloc_success = false; - } - - if (!alloc_success){ - char msg[] = "Could not allocate sufficient memory. Please make sure you have atleast 512Mb of RAM free. (This requirement will be relaxed in the future)."; - system_error_box(scratch, msg); - } -} - -internal void -load_app_code(Arena *scratch){ +load_app_code(Thread_Context *tctx){ App_Get_Functions *get_funcs = 0; + Scratch_Block scratch(tctx, Scratch_Share); if (system_load_library(scratch, &libraries.app_code, "4ed_app", LoadLibrary_BinaryDirectory)){ get_funcs = (App_Get_Functions*)system_get_proc(&libraries.app_code, "app_get_functions"); } @@ -70,7 +36,8 @@ global char custom_fail_version_msg[] = "Failed to load custom code due to missi global char custom_fail_missing_get_bindings_msg[] = "Failed to load custom code due to missing 'get_bindings' symbol. Try rebuilding with buildsuper."; internal void -load_custom_code(Arena *scratch){ +load_custom_code(Thread_Context *tctx){ + Scratch_Block scratch(tctx, Scratch_Share); local_persist char *default_file = "custom_4coder"; local_persist Load_Library_Location locations[] = { LoadLibrary_CurrentDirectory, @@ -121,17 +88,17 @@ load_custom_code(Arena *scratch){ //LOGF("Loaded custom file: %s\n", success_file); } -internal void -read_command_line(Arena *scratch, i32 argc, char **argv){ - Temp_Memory temp = begin_temp(scratch); +internal void* +read_command_line(Thread_Context *tctx, i32 argc, char **argv){ + Scratch_Block scratch(tctx, Scratch_Share); String_Const_u8 curdir = sysfunc.get_current_path(scratch); curdir = string_mod_replace_character(curdir, '\\', '/'); char **files = 0; i32 *file_count = 0; - app.read_command_line(&sysfunc, &memory_vars, curdir, &plat_settings, &files, &file_count, argc, argv); + void *result = app.read_command_line(tctx, &sysfunc, curdir, &plat_settings, &files, &file_count, argc, argv); sysshared_filter_real_files(scratch, files, file_count); - end_temp(temp); + return(result); } // BOTTOM diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index 6cc79e89..82e36d1e 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -150,7 +150,7 @@ struct Win32_Object{ }; struct Win32_Vars{ - Arena arena; + Thread_Context *tctx; Win32_Input_Chunk input_chunk; b8 lctrl_lalt_is_altgr; @@ -201,7 +201,6 @@ struct Win32_Vars{ global Win32_Vars win32vars; global Render_Target target; -global Application_Memory memory_vars; global Plat_Settings plat_settings; global Libraries libraries; @@ -1026,7 +1025,7 @@ Sys_Condition_Variable_Free_Sig(system_condition_variable_free){ internal LRESULT win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ LRESULT result = 0; - Arena *scratch = &win32vars.arena; + Scratch_Block scratch(win32vars.tctx); switch (uMsg){ case WM_MENUCHAR:break; @@ -1538,20 +1537,21 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // Memory init // + Thread_Context _tctx = {}; + thread_ctx_init(&_tctx, get_base_allocator_system(&sysfunc)); + + block_zero_struct(&win32vars); + win32vars.tctx = &_tctx; + + // TODO(allen): *arena; + target.arena = make_arena_system(&sysfunc); - memset(&win32vars, 0, sizeof(win32vars)); - memset(&target, 0, sizeof(target)); - memset(&memory_vars, 0, sizeof(memory_vars)); memset(&plat_settings, 0, sizeof(plat_settings)); - win32vars.arena = make_arena_system(&sysfunc); - memset(&libraries, 0, sizeof(libraries)); memset(&app, 0, sizeof(app)); memset(&custom_api, 0, sizeof(custom_api)); - memory_init(&win32vars.arena); - win32vars.cursor_show = MouseCursorShow_Always; win32vars.prev_cursor_show = MouseCursorShow_Always; @@ -1568,16 +1568,16 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS init_shared_vars(); - load_app_code(&win32vars.arena); + load_app_code(win32vars.tctx); win32vars.log_string = app.get_logger(&sysfunc); - read_command_line(&win32vars.arena, argc, argv); + void *base_ptr = read_command_line(win32vars.tctx, argc, argv); // // Load Custom Code // #if defined(FRED_SUPER) - load_custom_code(&win32vars.arena); + load_custom_code(win32vars.tctx); #else custom_api.get_bindings = get_bindings; #endif @@ -1630,7 +1630,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // if (!AddClipboardFormatListener(win32vars.window_handle)){ - win32_output_error_string(&win32vars.arena, ErrorString_UseLog); + Scratch_Block scratch(win32vars.tctx, Scratch_Share); + win32_output_error_string(scratch, ErrorString_UseLog); } win32vars.clip_max = KB(16); @@ -1638,7 +1639,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS win32vars.clipboard_sequence = GetClipboardSequenceNumber(); if (win32vars.clipboard_sequence == 0){ - win32_post_clipboard(&win32vars.arena, "", 0); + Scratch_Block scratch(win32vars.tctx, Scratch_Share); + win32_post_clipboard(scratch, "", 0); win32vars.clipboard_sequence = GetClipboardSequenceNumber(); win32vars.next_clipboard_is_self = 0; @@ -1648,7 +1650,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } } else{ - win32_read_clipboard_contents(&win32vars.arena); + Scratch_Block scratch(win32vars.tctx, Scratch_Share); + win32_read_clipboard_contents(scratch); } win32_keycode_init(); @@ -1673,11 +1676,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // { - Temp_Memory temp = begin_temp(&win32vars.arena); - String_Const_u8 curdir = sysfunc.get_current_path(&win32vars.arena); + Scratch_Block scratch(win32vars.tctx, Scratch_Share); + String_Const_u8 curdir = sysfunc.get_current_path(scratch); curdir = string_mod_replace_character(curdir, '\\', '/'); - app.init(&sysfunc, &target, &memory_vars, win32vars.clipboard_contents, curdir, custom_api); - end_temp(temp); + app.init(&sysfunc, &target, base_ptr, win32vars.clipboard_contents, curdir, custom_api); } // @@ -1863,7 +1865,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } else{ for (i32 R = 0; R < 4; ++R){ - if (win32_read_clipboard_contents(&win32vars.arena)){ + Scratch_Block scratch(win32vars.tctx, Scratch_Share); + if (win32_read_clipboard_contents(scratch)){ input.clipboard_changed = true; break; } @@ -1880,7 +1883,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // NOTE(allen): Application Core Update Application_Step_Result result = {}; if (app.step != 0){ - result = app.step(&sysfunc, &target, &memory_vars, &input); + result = app.step(&sysfunc, &target, base_ptr, &input); } else{ //LOG("app.step == 0 -- skipping\n"); @@ -1893,12 +1896,14 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // NOTE(allen): Post New Clipboard Content if (win32vars.clip_post.size > 0){ - win32_post_clipboard(&win32vars.arena, (char*)win32vars.clip_post.str, (i32)win32vars.clip_post.size); + Scratch_Block scratch(win32vars.tctx, Scratch_Share); + win32_post_clipboard(scratch, (char*)win32vars.clip_post.str, (i32)win32vars.clip_post.size); } // NOTE(allen): Switch to New Title if (result.has_new_title){ - SetWindowText_utf8(&win32vars.arena, win32vars.window_handle, (u8*)result.title_string); + Scratch_Block scratch(win32vars.tctx, Scratch_Share); + SetWindowText_utf8(scratch, win32vars.window_handle, (u8*)result.title_string); } // NOTE(allen): Switch to New Cursor