New heap up and running.

master
Allen Webster 2018-08-18 01:16:52 -07:00
parent ace76a2d3f
commit a339c9fc9e
37 changed files with 1258 additions and 1191 deletions

View File

@ -6,7 +6,7 @@
// TOP
static Partition global_part;
static General_Memory global_general;
static Heap global_heap;
static void
unlock_jump_buffer(void){
@ -226,13 +226,14 @@ CUSTOM_DOC("Switch to a named key binding map.")
static void
default_4coder_initialize(Application_Links *app, int32_t override_font_size, bool32 override_hinting){
int32_t part_size = (32 << 20);
int32_t general_size = (4 << 20);
int32_t heap_size = ( 4 << 20);
void *part_mem = memory_allocate(app, part_size);
global_part = make_part(part_mem, part_size);
void *general_mem = memory_allocate(app, general_size);
general_memory_open(&global_general, general_mem, general_size);
void *heap_mem = memory_allocate(app, heap_size);
heap_init(&global_heap);
heap_extend(&global_heap, heap_mem, heap_size);
static const char message[] = ""
"Welcome to " VERSION "\n"

View File

@ -18,10 +18,14 @@
#define FSTRING_IMPLEMENTATION
#include "4coder_lib/4coder_string.h"
#include "4coder_lib/4coder_table.h"
#include "4coder_lib/4coder_mem.h"
#include "4coder_lib/4coder_arena.h"
#include "4coder_lib/4coder_heap.h"
#include "4coder_lib/4coder_utf8.h"
#include "4coder_lib/4cpp_lexer.h"
#include "4coder_lib/4coder_arena.cpp"
#include "4coder_lib/4coder_heap.cpp"
#include "4coder_ui_helper.h"
#include "4coder_helper.h"
#include "4coder_default_framework.h"

View File

@ -7,7 +7,9 @@
#if !defined(FCODER_FILE_ENUMERATOR_CPP)
#define FCODER_FILE_ENUMERATOR_CPP
#include "4coder_lib/4coder_mem.h"
#include "4coder_lib/4coder_arena.h"
#include "4coder_lib/4coder_arena.cpp"
#include "4coder_os_comp_cracking.h"
#define FSTRING_IMPLEMENTATION
#include "4coder_lib/4coder_string.h"

View File

@ -21,7 +21,7 @@ struct Application_Links;
#define GET_BUFFER_BY_MARKER_HANDLE_SIG(n) Buffer_Summary n(Application_Links *app, Managed_Object marker_object, Access_Flag access)
#define BUFFER_SET_MARKERS_SIG(n) bool32 n(Application_Links *app, Managed_Object marker_object, uint32_t first_marker_index, uint32_t marker_count, Marker *source_markers)
#define BUFFER_GET_MARKERS_SIG(n) bool32 n(Application_Links *app, Managed_Object marker_object, uint32_t first_marker_index, uint32_t marker_count, Marker *markers_out)
#define BUFFER_REMOVE_MARKERS_SIG(n) bool32 n(Application_Links *app, Managed_Object marker)
#define BUFFER_REMOVE_MARKERS_SIG(n) bool32 n(Application_Links *app, Managed_Object marker_object)
#define BUFFER_GET_SETTING_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t *value_out)
#define BUFFER_SET_SETTING_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value)
#define BUFFER_GET_DYNAMIC_SCOPE_SIG(n) Dynamic_Scope n(Application_Links *app, Buffer_ID buffer_id)
@ -61,6 +61,9 @@ struct Application_Links;
#define MANAGED_VARIABLE_CREATE_OR_GET_ID_SIG(n) int32_t n(Application_Links *app, char *null_terminated_name, uint64_t default_value)
#define MANAGED_VARIABLE_SET_SIG(n) bool32 n(Application_Links *app, Dynamic_Scope scope, Managed_Variable_ID location, uint64_t value)
#define MANAGED_VARIABLE_GET_SIG(n) bool32 n(Application_Links *app, Dynamic_Scope scope, Managed_Variable_ID location, uint64_t *value_out)
#define MANAGED_MEMORY_ALLOC_SIG(n) Managed_Object n(Application_Links *app, Dynamic_Scope scope, int32_t size)
#define MANAGED_MEMORY_SET_SIG(n) bool32 n(Application_Links *app, Managed_Object object, uint32_t start, uint32_t size, void *mem)
#define MANAGED_MEMORY_GET_SIG(n) bool32 n(Application_Links *app, Managed_Object object, uint32_t start, uint32_t size, void *mem_out)
#define GET_USER_INPUT_SIG(n) User_Input n(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type)
#define GET_COMMAND_INPUT_SIG(n) User_Input n(Application_Links *app)
#define GET_MOUSE_STATE_SIG(n) Mouse_State n(Application_Links *app)
@ -162,6 +165,9 @@ typedef MANAGED_VARIABLE_GET_ID_SIG(Managed_Variable_Get_ID_Function);
typedef MANAGED_VARIABLE_CREATE_OR_GET_ID_SIG(Managed_Variable_Create_Or_Get_ID_Function);
typedef MANAGED_VARIABLE_SET_SIG(Managed_Variable_Set_Function);
typedef MANAGED_VARIABLE_GET_SIG(Managed_Variable_Get_Function);
typedef MANAGED_MEMORY_ALLOC_SIG(Managed_Memory_Alloc_Function);
typedef MANAGED_MEMORY_SET_SIG(Managed_Memory_Set_Function);
typedef MANAGED_MEMORY_GET_SIG(Managed_Memory_Get_Function);
typedef GET_USER_INPUT_SIG(Get_User_Input_Function);
typedef GET_COMMAND_INPUT_SIG(Get_Command_Input_Function);
typedef GET_MOUSE_STATE_SIG(Get_Mouse_State_Function);
@ -265,6 +271,9 @@ Managed_Variable_Get_ID_Function *managed_variable_get_id;
Managed_Variable_Create_Or_Get_ID_Function *managed_variable_create_or_get_id;
Managed_Variable_Set_Function *managed_variable_set;
Managed_Variable_Get_Function *managed_variable_get;
Managed_Memory_Alloc_Function *managed_memory_alloc;
Managed_Memory_Set_Function *managed_memory_set;
Managed_Memory_Get_Function *managed_memory_get;
Get_User_Input_Function *get_user_input;
Get_Command_Input_Function *get_command_input;
Get_Mouse_State_Function *get_mouse_state;
@ -367,6 +376,9 @@ Managed_Variable_Get_ID_Function *managed_variable_get_id_;
Managed_Variable_Create_Or_Get_ID_Function *managed_variable_create_or_get_id_;
Managed_Variable_Set_Function *managed_variable_set_;
Managed_Variable_Get_Function *managed_variable_get_;
Managed_Memory_Alloc_Function *managed_memory_alloc_;
Managed_Memory_Set_Function *managed_memory_set_;
Managed_Memory_Get_Function *managed_memory_get_;
Get_User_Input_Function *get_user_input_;
Get_Command_Input_Function *get_command_input_;
Get_Mouse_State_Function *get_mouse_state_;
@ -477,6 +489,9 @@ app_links->managed_variable_get_id_ = Managed_Variable_Get_ID;\
app_links->managed_variable_create_or_get_id_ = Managed_Variable_Create_Or_Get_ID;\
app_links->managed_variable_set_ = Managed_Variable_Set;\
app_links->managed_variable_get_ = Managed_Variable_Get;\
app_links->managed_memory_alloc_ = Managed_Memory_Alloc;\
app_links->managed_memory_set_ = Managed_Memory_Set;\
app_links->managed_memory_get_ = Managed_Memory_Get;\
app_links->get_user_input_ = Get_User_Input;\
app_links->get_command_input_ = Get_Command_Input;\
app_links->get_mouse_state_ = Get_Mouse_State;\
@ -539,7 +554,7 @@ static inline Managed_Object buffer_add_markers(Application_Links *app, Buffer_I
static inline Buffer_Summary get_buffer_by_marker_handle(Application_Links *app, Managed_Object marker_object, Access_Flag access){return(app->get_buffer_by_marker_handle(app, marker_object, access));}
static inline bool32 buffer_set_markers(Application_Links *app, Managed_Object marker_object, uint32_t first_marker_index, uint32_t marker_count, Marker *source_markers){return(app->buffer_set_markers(app, marker_object, first_marker_index, marker_count, source_markers));}
static inline bool32 buffer_get_markers(Application_Links *app, Managed_Object marker_object, uint32_t first_marker_index, uint32_t marker_count, Marker *markers_out){return(app->buffer_get_markers(app, marker_object, first_marker_index, marker_count, markers_out));}
static inline bool32 buffer_remove_markers(Application_Links *app, Managed_Object marker){return(app->buffer_remove_markers(app, marker));}
static inline bool32 buffer_remove_markers(Application_Links *app, Managed_Object marker_object){return(app->buffer_remove_markers(app, marker_object));}
static inline bool32 buffer_get_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t *value_out){return(app->buffer_get_setting(app, buffer, setting, value_out));}
static inline bool32 buffer_set_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value){return(app->buffer_set_setting(app, buffer, setting, value));}
static inline Dynamic_Scope buffer_get_dynamic_scope(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_get_dynamic_scope(app, buffer_id));}
@ -579,6 +594,9 @@ static inline Managed_Variable_ID managed_variable_get_id(Application_Links *app
static inline int32_t managed_variable_create_or_get_id(Application_Links *app, char *null_terminated_name, uint64_t default_value){return(app->managed_variable_create_or_get_id(app, null_terminated_name, default_value));}
static inline bool32 managed_variable_set(Application_Links *app, Dynamic_Scope scope, Managed_Variable_ID location, uint64_t value){return(app->managed_variable_set(app, scope, location, value));}
static inline bool32 managed_variable_get(Application_Links *app, Dynamic_Scope scope, Managed_Variable_ID location, uint64_t *value_out){return(app->managed_variable_get(app, scope, location, value_out));}
static inline Managed_Object managed_memory_alloc(Application_Links *app, Dynamic_Scope scope, int32_t size){return(app->managed_memory_alloc(app, scope, size));}
static inline bool32 managed_memory_set(Application_Links *app, Managed_Object object, uint32_t start, uint32_t size, void *mem){return(app->managed_memory_set(app, object, start, size, mem));}
static inline bool32 managed_memory_get(Application_Links *app, Managed_Object object, uint32_t start, uint32_t size, void *mem_out){return(app->managed_memory_get(app, object, start, size, mem_out));}
static inline User_Input get_user_input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type){return(app->get_user_input(app, get_type, abort_type));}
static inline User_Input get_command_input(Application_Links *app){return(app->get_command_input(app));}
static inline Mouse_State get_mouse_state(Application_Links *app){return(app->get_mouse_state(app));}
@ -641,7 +659,7 @@ static inline Managed_Object buffer_add_markers(Application_Links *app, Buffer_I
static inline Buffer_Summary get_buffer_by_marker_handle(Application_Links *app, Managed_Object marker_object, Access_Flag access){return(app->get_buffer_by_marker_handle_(app, marker_object, access));}
static inline bool32 buffer_set_markers(Application_Links *app, Managed_Object marker_object, uint32_t first_marker_index, uint32_t marker_count, Marker *source_markers){return(app->buffer_set_markers_(app, marker_object, first_marker_index, marker_count, source_markers));}
static inline bool32 buffer_get_markers(Application_Links *app, Managed_Object marker_object, uint32_t first_marker_index, uint32_t marker_count, Marker *markers_out){return(app->buffer_get_markers_(app, marker_object, first_marker_index, marker_count, markers_out));}
static inline bool32 buffer_remove_markers(Application_Links *app, Managed_Object marker){return(app->buffer_remove_markers_(app, marker));}
static inline bool32 buffer_remove_markers(Application_Links *app, Managed_Object marker_object){return(app->buffer_remove_markers_(app, marker_object));}
static inline bool32 buffer_get_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t *value_out){return(app->buffer_get_setting_(app, buffer, setting, value_out));}
static inline bool32 buffer_set_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value){return(app->buffer_set_setting_(app, buffer, setting, value));}
static inline Dynamic_Scope buffer_get_dynamic_scope(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_get_dynamic_scope_(app, buffer_id));}
@ -681,6 +699,9 @@ static inline Managed_Variable_ID managed_variable_get_id(Application_Links *app
static inline int32_t managed_variable_create_or_get_id(Application_Links *app, char *null_terminated_name, uint64_t default_value){return(app->managed_variable_create_or_get_id_(app, null_terminated_name, default_value));}
static inline bool32 managed_variable_set(Application_Links *app, Dynamic_Scope scope, Managed_Variable_ID location, uint64_t value){return(app->managed_variable_set_(app, scope, location, value));}
static inline bool32 managed_variable_get(Application_Links *app, Dynamic_Scope scope, Managed_Variable_ID location, uint64_t *value_out){return(app->managed_variable_get_(app, scope, location, value_out));}
static inline Managed_Object managed_memory_alloc(Application_Links *app, Dynamic_Scope scope, int32_t size){return(app->managed_memory_alloc_(app, scope, size));}
static inline bool32 managed_memory_set(Application_Links *app, Managed_Object object, uint32_t start, uint32_t size, void *mem){return(app->managed_memory_set_(app, object, start, size, mem));}
static inline bool32 managed_memory_get(Application_Links *app, Managed_Object object, uint32_t start, uint32_t size, void *mem_out){return(app->managed_memory_get_(app, object, start, size, mem_out));}
static inline User_Input get_user_input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type){return(app->get_user_input_(app, get_type, abort_type));}
static inline User_Input get_command_input(Application_Links *app){return(app->get_command_input_(app));}
static inline Mouse_State get_mouse_state(Application_Links *app){return(app->get_mouse_state_(app));}

View File

@ -263,21 +263,21 @@ static Command_Metadata fcoder_metacmd_table[202] = {
{ 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", 30, 1168 },
{ 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", 30, 1175 },
{ PROC_LINKS(goto_first_jump_direct, 0), "goto_first_jump_direct", 22, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "w:\\4ed\\code\\4coder_jump_direct.cpp", 37, 84 },
{ 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", 37, 532 },
{ PROC_LINKS(goto_first_jump_sticky, 0), "goto_first_jump_sticky", 22, "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", 37, 514 },
{ 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", 37, 517 },
{ PROC_LINKS(goto_first_jump_sticky, 0), "goto_first_jump_sticky", 22, "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", 37, 499 },
{ PROC_LINKS(goto_jump_at_cursor_direct, 0), "goto_jump_at_cursor_direct", 26, "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_direct.cpp", 37, 8 },
{ PROC_LINKS(goto_jump_at_cursor_same_panel_direct, 0), "goto_jump_at_cursor_same_panel_direct", 37, "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..", 168, "w:\\4ed\\code\\4coder_jump_direct.cpp", 37, 29 },
{ PROC_LINKS(goto_jump_at_cursor_same_panel_sticky, 0), "goto_jump_at_cursor_same_panel_sticky", 37, "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", 37, 360 },
{ PROC_LINKS(goto_jump_at_cursor_sticky, 0), "goto_jump_at_cursor_sticky", 26, "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", 37, 332 },
{ PROC_LINKS(goto_jump_at_cursor_same_panel_sticky, 0), "goto_jump_at_cursor_same_panel_sticky", 37, "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", 37, 345 },
{ PROC_LINKS(goto_jump_at_cursor_sticky, 0), "goto_jump_at_cursor_sticky", 26, "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", 37, 317 },
{ PROC_LINKS(goto_line, 0), "goto_line", 9, "Queries the user for a number, and jumps the cursor to the corresponding line.", 78, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 585 },
{ PROC_LINKS(goto_next_jump_direct, 0), "goto_next_jump_direct", 21, "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_direct.cpp", 37, 48 },
{ PROC_LINKS(goto_next_jump_no_skips_direct, 0), "goto_next_jump_no_skips_direct", 30, "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_direct.cpp", 37, 66 },
{ PROC_LINKS(goto_next_jump_no_skips_sticky, 0), "goto_next_jump_no_skips_sticky", 30, "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", 37, 483 },
{ PROC_LINKS(goto_next_jump_sticky, 0), "goto_next_jump_sticky", 21, "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", 37, 453 },
{ PROC_LINKS(goto_next_jump_no_skips_sticky, 0), "goto_next_jump_no_skips_sticky", 30, "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", 37, 468 },
{ PROC_LINKS(goto_next_jump_sticky, 0), "goto_next_jump_sticky", 21, "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", 37, 438 },
{ PROC_LINKS(goto_prev_jump_direct, 0), "goto_prev_jump_direct", 21, "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_direct.cpp", 37, 57 },
{ PROC_LINKS(goto_prev_jump_no_skips_direct, 0), "goto_prev_jump_no_skips_direct", 30, "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_direct.cpp", 37, 75 },
{ PROC_LINKS(goto_prev_jump_no_skips_sticky, 0), "goto_prev_jump_no_skips_sticky", 30, "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", 37, 499 },
{ PROC_LINKS(goto_prev_jump_sticky, 0), "goto_prev_jump_sticky", 21, "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", 37, 469 },
{ PROC_LINKS(goto_prev_jump_no_skips_sticky, 0), "goto_prev_jump_no_skips_sticky", 30, "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", 37, 484 },
{ PROC_LINKS(goto_prev_jump_sticky, 0), "goto_prev_jump_sticky", 21, "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", 37, 454 },
{ PROC_LINKS(hide_filebar, 0), "hide_filebar", 12, "Sets the current view to hide it's filebar.", 43, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 471 },
{ PROC_LINKS(hide_scrollbar, 0), "hide_scrollbar", 14, "Sets the current view to hide it's scrollbar.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 457 },
{ PROC_LINKS(highlight_next_scope_absolute, 0), "highlight_next_scope_absolute", 29, "Finds the first scope started by '{' after the cursor and puts the cursor and mark on the '{' and '}'.", 102, "w:\\4ed\\code\\4coder_scope_commands.cpp", 40, 363 },
@ -286,41 +286,41 @@ static Command_Metadata fcoder_metacmd_table[202] = {
{ PROC_LINKS(if0_off, 0), "if0_off", 7, "Surround the range between the cursor and mark with an '#if 0' and an '#endif'", 78, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 49, 82 },
{ PROC_LINKS(increase_face_size, 0), "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 519 },
{ PROC_LINKS(increase_line_wrap, 0), "increase_line_wrap", 18, "Increases the current buffer's width for line wrapping.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 497 },
{ PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\4coder_lists.cpp", 31, 647 },
{ PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\4coder_lists.cpp", 31, 749 },
{ PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\4coder_lists.cpp", 31, 776 },
{ 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", 31, 716 },
{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "w:\\4ed\\code\\4coder_lists.cpp", 31, 629 },
{ PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\4coder_lists.cpp", 31, 646 },
{ PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\4coder_lists.cpp", 31, 748 },
{ PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\4coder_lists.cpp", 31, 775 },
{ 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", 31, 715 },
{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "w:\\4ed\\code\\4coder_lists.cpp", 31, 628 },
{ PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 1444 },
{ PROC_LINKS(left_adjust_view, 0), "left_adjust_view", 16, "Sets the left size of the view near the x position of the cursor.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 135 },
{ 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", 39, 318 },
{ PROC_LINKS(list_all_locations, 0), "list_all_locations", 18, "Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.", 99, "w:\\4ed\\code\\4coder_search.cpp", 32, 741 },
{ PROC_LINKS(list_all_locations_case_insensitive, 0), "list_all_locations_case_insensitive", 35, "Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.", 101, "w:\\4ed\\code\\4coder_search.cpp", 32, 753 },
{ PROC_LINKS(list_all_locations_of_identifier, 0), "list_all_locations_of_identifier", 32, "Reads a token or word under the cursor and lists all exact case-sensitive mathces in all open buffers.", 102, "w:\\4ed\\code\\4coder_search.cpp", 32, 765 },
{ PROC_LINKS(list_all_locations_of_identifier_case_insensitive, 0), "list_all_locations_of_identifier_case_insensitive", 49, "Reads a token or word under the cursor and lists all exact case-insensitive mathces in all open buffers.", 104, "w:\\4ed\\code\\4coder_search.cpp", 32, 771 },
{ PROC_LINKS(list_all_locations_of_selection, 0), "list_all_locations_of_selection", 31, "Reads the string in the selected range and lists all exact case-sensitive mathces in all open buffers.", 102, "w:\\4ed\\code\\4coder_search.cpp", 32, 777 },
{ 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", 32, 783 },
{ 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", 32, 789 },
{ 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", 32, 800 },
{ PROC_LINKS(list_all_substring_locations, 0), "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "w:\\4ed\\code\\4coder_search.cpp", 32, 747 },
{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "w:\\4ed\\code\\4coder_search.cpp", 32, 759 },
{ PROC_LINKS(list_all_locations, 0), "list_all_locations", 18, "Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.", 99, "w:\\4ed\\code\\4coder_search.cpp", 32, 747 },
{ PROC_LINKS(list_all_locations_case_insensitive, 0), "list_all_locations_case_insensitive", 35, "Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.", 101, "w:\\4ed\\code\\4coder_search.cpp", 32, 759 },
{ PROC_LINKS(list_all_locations_of_identifier, 0), "list_all_locations_of_identifier", 32, "Reads a token or word under the cursor and lists all exact case-sensitive mathces in all open buffers.", 102, "w:\\4ed\\code\\4coder_search.cpp", 32, 771 },
{ PROC_LINKS(list_all_locations_of_identifier_case_insensitive, 0), "list_all_locations_of_identifier_case_insensitive", 49, "Reads a token or word under the cursor and lists all exact case-insensitive mathces in all open buffers.", 104, "w:\\4ed\\code\\4coder_search.cpp", 32, 777 },
{ PROC_LINKS(list_all_locations_of_selection, 0), "list_all_locations_of_selection", 31, "Reads the string in the selected range and lists all exact case-sensitive mathces in all open buffers.", 102, "w:\\4ed\\code\\4coder_search.cpp", 32, 783 },
{ 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", 32, 789 },
{ 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", 32, 795 },
{ 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", 32, 806 },
{ PROC_LINKS(list_all_substring_locations, 0), "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "w:\\4ed\\code\\4coder_search.cpp", 32, 753 },
{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "w:\\4ed\\code\\4coder_search.cpp", 32, 765 },
{ 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", 31, 17 },
{ PROC_LINKS(lister__backspace_text_field, 0), "lister__backspace_text_field", 28, "A lister mode command that dispatches to the lister's backspace text field handler.", 83, "w:\\4ed\\code\\4coder_lists.cpp", 31, 44 },
{ PROC_LINKS(lister__backspace_text_field__default, 0), "lister__backspace_text_field__default", 37, "A lister mode command that backspaces one character from the text field.", 72, "w:\\4ed\\code\\4coder_lists.cpp", 31, 149 },
{ 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", 31, 221 },
{ PROC_LINKS(lister__mouse_press, 0), "lister__mouse_press", 19, "A lister mode command that beings a click interaction with a list item under the mouse.", 87, "w:\\4ed\\code\\4coder_lists.cpp", 31, 89 },
{ PROC_LINKS(lister__mouse_release, 0), "lister__mouse_release", 21, "A lister mode command that ends a click interaction with a list item under the mouse, possibly activating it.", 109, "w:\\4ed\\code\\4coder_lists.cpp", 31, 101 },
{ PROC_LINKS(lister__move_down, 0), "lister__move_down", 17, "A lister mode command that dispatches to the lister's navigate down handler.", 76, "w:\\4ed\\code\\4coder_lists.cpp", 31, 64 },
{ PROC_LINKS(lister__move_down__default, 0), "lister__move_down__default", 26, "A lister mode command that moves the highlighted item one down in the list.", 75, "w:\\4ed\\code\\4coder_lists.cpp", 31, 180 },
{ PROC_LINKS(lister__move_up, 0), "lister__move_up", 15, "A lister mode command that dispatches to the lister's navigate up handler.", 74, "w:\\4ed\\code\\4coder_lists.cpp", 31, 54 },
{ PROC_LINKS(lister__move_up__default, 0), "lister__move_up__default", 24, "A lister mode command that moves the highlighted item one up in the list.", 73, "w:\\4ed\\code\\4coder_lists.cpp", 31, 164 },
{ PROC_LINKS(lister__backspace_text_field, 0), "lister__backspace_text_field", 28, "A lister mode command that dispatches to the lister's backspace text field handler.", 83, "w:\\4ed\\code\\4coder_lists.cpp", 31, 43 },
{ PROC_LINKS(lister__backspace_text_field__default, 0), "lister__backspace_text_field__default", 37, "A lister mode command that backspaces one character from the text field.", 72, "w:\\4ed\\code\\4coder_lists.cpp", 31, 148 },
{ 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", 31, 220 },
{ PROC_LINKS(lister__mouse_press, 0), "lister__mouse_press", 19, "A lister mode command that beings a click interaction with a list item under the mouse.", 87, "w:\\4ed\\code\\4coder_lists.cpp", 31, 88 },
{ PROC_LINKS(lister__mouse_release, 0), "lister__mouse_release", 21, "A lister mode command that ends a click interaction with a list item under the mouse, possibly activating it.", 109, "w:\\4ed\\code\\4coder_lists.cpp", 31, 100 },
{ PROC_LINKS(lister__move_down, 0), "lister__move_down", 17, "A lister mode command that dispatches to the lister's navigate down handler.", 76, "w:\\4ed\\code\\4coder_lists.cpp", 31, 63 },
{ PROC_LINKS(lister__move_down__default, 0), "lister__move_down__default", 26, "A lister mode command that moves the highlighted item one down in the list.", 75, "w:\\4ed\\code\\4coder_lists.cpp", 31, 179 },
{ PROC_LINKS(lister__move_up, 0), "lister__move_up", 15, "A lister mode command that dispatches to the lister's navigate up handler.", 74, "w:\\4ed\\code\\4coder_lists.cpp", 31, 53 },
{ PROC_LINKS(lister__move_up__default, 0), "lister__move_up__default", 24, "A lister mode command that moves the highlighted item one up in the list.", 73, "w:\\4ed\\code\\4coder_lists.cpp", 31, 163 },
{ 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", 31, 8 },
{ PROC_LINKS(lister__repaint, 0), "lister__repaint", 15, "A lister mode command that updates the lists UI data.", 53, "w:\\4ed\\code\\4coder_lists.cpp", 31, 118 },
{ PROC_LINKS(lister__wheel_scroll, 0), "lister__wheel_scroll", 20, "A lister mode command that scrolls the list in response to the mouse wheel.", 75, "w:\\4ed\\code\\4coder_lists.cpp", 31, 74 },
{ 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", 31, 34 },
{ PROC_LINKS(lister__write_character__default, 0), "lister__write_character__default", 32, "A lister mode command that inserts a new character to the text field.", 69, "w:\\4ed\\code\\4coder_lists.cpp", 31, 129 },
{ 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", 31, 196 },
{ 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", 31, 256 },
{ PROC_LINKS(lister__repaint, 0), "lister__repaint", 15, "A lister mode command that updates the lists UI data.", 53, "w:\\4ed\\code\\4coder_lists.cpp", 31, 117 },
{ PROC_LINKS(lister__wheel_scroll, 0), "lister__wheel_scroll", 20, "A lister mode command that scrolls the list in response to the mouse wheel.", 75, "w:\\4ed\\code\\4coder_lists.cpp", 31, 73 },
{ 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", 31, 33 },
{ PROC_LINKS(lister__write_character__default, 0), "lister__write_character__default", 32, "A lister mode command that inserts a new character to the text field.", 69, "w:\\4ed\\code\\4coder_lists.cpp", 31, 128 },
{ 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", 31, 195 },
{ 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", 31, 255 },
{ 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", 42, 1071 },
{ 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", 39, 1132 },
{ PROC_LINKS(move_down, 0), "move_down", 9, "Moves the cursor down one line.", 31, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 250 },
@ -334,11 +334,11 @@ static Command_Metadata fcoder_metacmd_table[202] = {
{ PROC_LINKS(move_up_10, 0), "move_up_10", 10, "Moves the cursor up ten lines.", 30, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 256 },
{ PROC_LINKS(newline_or_goto_position_direct, 0), "newline_or_goto_position_direct", 31, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "w:\\4ed\\code\\4coder_jump_direct.cpp", 37, 101 },
{ PROC_LINKS(newline_or_goto_position_same_panel_direct, 0), "newline_or_goto_position_same_panel_direct", 42, "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_direct.cpp", 37, 116 },
{ PROC_LINKS(newline_or_goto_position_same_panel_sticky, 0), "newline_or_goto_position_same_panel_sticky", 42, "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", 37, 570 },
{ PROC_LINKS(newline_or_goto_position_sticky, 0), "newline_or_goto_position_sticky", 31, "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", 37, 555 },
{ PROC_LINKS(newline_or_goto_position_same_panel_sticky, 0), "newline_or_goto_position_same_panel_sticky", 42, "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", 37, 555 },
{ PROC_LINKS(newline_or_goto_position_sticky, 0), "newline_or_goto_position_sticky", 31, "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", 37, 540 },
{ 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", 42, 1055 },
{ 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", 42, 1062 },
{ PROC_LINKS(open_color_tweaker, 0), "open_color_tweaker", 18, "Opens the 4coder theme selector list.", 37, "w:\\4ed\\code\\4coder_lists.cpp", 31, 792 },
{ PROC_LINKS(open_color_tweaker, 0), "open_color_tweaker", 18, "Opens the 4coder theme selector list.", 37, "w:\\4ed\\code\\4coder_lists.cpp", 31, 791 },
{ 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", 39, 1351 },
{ 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", 39, 1502 },
{ PROC_LINKS(open_long_braces, 0), "open_long_braces", 16, "At the cursor, insert a '{' and '}' separated by a blank line.", 62, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 49, 58 },
@ -416,7 +416,7 @@ static Command_Metadata fcoder_metacmd_table[202] = {
{ PROC_LINKS(toggle_virtual_whitespace, 0), "toggle_virtual_whitespace", 25, "Toggles the current buffer's virtual whitespace status.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 543 },
{ PROC_LINKS(undo, 0), "undo", 4, "Advances backwards through the undo history.", 44, "w:\\4ed\\code\\4coder_base_commands.cpp", 39, 1453 },
{ 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", 39, 1401 },
{ 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", 32, 820 },
{ 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", 32, 826 },
{ PROC_LINKS(write_and_auto_tab, 0), "write_and_auto_tab", 18, "Inserts a character and auto-indents the line on which the cursor sits.", 71, "w:\\4ed\\code\\4coder_auto_indent.cpp", 37, 745 },
{ PROC_LINKS(write_block, 0), "write_block", 11, "At the cursor, insert a block comment.", 38, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 49, 106 },
{ 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", 39, 33 },

View File

@ -1333,5 +1333,66 @@ push_string_copy(Partition *arena, char *str){
return(push_string_copy(arena, make_string_slowly(str)));
}
static void
sort_pairs_by_key__quick(Sort_Pair_i32 *pairs, int32_t first, int32_t one_past_last){
int32_t dif = one_past_last - first;
if (dif >= 2){
int32_t pivot = one_past_last - 1;
int32_t pivot_key = pairs[pivot].key;
int32_t j = first;
bool32 interleave = false;
for (int32_t i = first; i < pivot; i += 1){
int32_t key = pairs[i].key;
if (key < pivot_key){
pairs[i].key = pairs[j].key;
pairs[j].key = key;
j += 1;
}
else if (key == pivot_key){
if (interleave){
pairs[i].key = pairs[j].key;
pairs[j].key = key;
j += 1;
}
interleave = !interleave;
}
}
pairs[pivot].key = pairs[j].key;
pairs[j].key = pivot_key;
sort_pairs_by_key__quick(pairs, first, j);
sort_pairs_by_key__quick(pairs, j + 1, one_past_last);
}
}
static void
sort_pairs_by_key(Sort_Pair_i32 *pairs, int32_t count){
sort_pairs_by_key__quick(pairs, 0, count);
}
static Range_Array
get_ranges_of_duplicate_keys(Partition *arena, int32_t *keys, int32_t stride, int32_t count){
Range_Array result = {0};
result.ranges = push_array(arena, Range, 0);
uint8_t *ptr = (uint8_t*)keys;
int32_t start_i = 0;
for (int32_t i = 1; i <= count; i += 1){
bool32 is_end = false;
if (i == count){
is_end = true;
}
else if (*(int32_t*)(ptr + i*stride) != *(int32_t*)(ptr + start_i*stride)){
is_end = true;
}
if (is_end){
Range *new_range = push_array(arena, Range, 1);
new_range->first = start_i;
new_range->one_past_last = i;
start_i = i;
}
}
result.count = (int32_t)(push_array(arena, Range, 0) - result.ranges);
return(result);
}
// BOTTOM

View File

@ -125,6 +125,13 @@ struct Stream_Tokens{
int32_t count, token_count;
};
////////////////////////////////
struct Sort_Pair_i32{
int32_t index;
int32_t key;
};
#endif
// BOTTOM

View File

@ -90,148 +90,84 @@ parse_buffer_to_jump_array(Application_Links *app, Partition *arena, Buffer_Summ
return(result);
}
static Range_Array
jump_array_mark_buffer_ranges(Partition *arena, Sticky_Jump_Array jumps){
Range_Array result = {0};
result.ranges = push_array(arena, Range, 0);
int32_t start_i = 0;
for (int32_t i = 1; i <= jumps.count; i += 1){
bool32 is_end = false;
if (i == jumps.count){
is_end = true;
}
else if (jumps.jumps[i].jump_buffer_id != jumps.jumps[start_i].jump_buffer_id){
is_end = true;
}
if (is_end){
Range *new_range = push_array(arena, Range, 1);
new_range->first = start_i;
new_range->one_past_last = i;
start_i = i;
}
}
result.count = (int32_t)(push_array(arena, Range, 0) - result.ranges);
return(result);
}
static char sticky_jump_marker_handle_var[] = "DEFAULT.sticky_jump_marker_handle";
static int32_t sticky_jump_marker_handle_loc;
#if 1
static void
init_marker_list(Application_Links *app, Partition *part, General_Memory *general, Buffer_ID buffer_id,
init_marker_list(Application_Links *app, Partition *scratch, Heap *heap, Buffer_ID buffer_id,
Marker_List *list){
Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll);
Temp_Memory temp = begin_temp_memory(part);
Sticky_Jump_Array jumps = parse_buffer_to_jump_array(app, part, buffer);
Range_Array buffer_ranges = jump_array_mark_buffer_ranges(part, jumps);
Temp_Memory temp = begin_temp_memory(scratch);
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);
Sort_Pair_i32 *range_index_buffer_id_pairs = push_array(scratch, Sort_Pair_i32, buffer_ranges.count);
for (int32_t i = 0; i < buffer_ranges.count; i += 1){
range_index_buffer_id_pairs[i].index = i;
range_index_buffer_id_pairs[i].key = jumps.jumps[buffer_ranges.ranges[i].first].jump_buffer_id;
}
sort_pairs_by_key(range_index_buffer_id_pairs, buffer_ranges.count);
Range_Array grouped_buffer_ranges = get_ranges_of_duplicate_keys(scratch,
&range_index_buffer_id_pairs->key,
sizeof(*range_index_buffer_id_pairs),
buffer_ranges.count);
Dynamic_Scope scope_array[2];
Sticky_Jump_Stored *stored = push_array(scratch, Sticky_Jump_Stored, jumps.count);
Dynamic_Scope scope_array[2] = {0};
scope_array[0] = buffer_get_dynamic_scope(app, buffer_id);
Managed_Object list_sentinel = managed_list_node_alloc(app, scope_array[0]);
for (int32_t i = 0; i < buffer_ranges.count; i += 1){
Range range = buffer_ranges.ranges[i];
Buffer_ID target_buffer_id = jumps.jumps[range.first].jump_buffer_id;
int32_t jump_count = range.one_past_last - range.first;
for (int32_t i = 0; i < grouped_buffer_ranges.count; i += 1){
Range buffer_range_indices = grouped_buffer_ranges.ranges[i];
Temp_Memory marker_temp = begin_temp_memory(scratch);
Marker *markers = push_array(scratch, Marker, 0);
int32_t total_jump_count = 0;
Buffer_ID target_buffer_id = 0;
for (int32_t j = buffer_range_indices.first;
j < buffer_range_indices.one_past_last;
j += 1){
int32_t range_index = range_index_buffer_id_pairs[j].index;
Range range = buffer_ranges.ranges[range_index];
total_jump_count += range.one_past_last - range.first;
if (target_buffer_id == 0){
target_buffer_id = jumps.jumps[range.first].jump_buffer_id;
}
for (int32_t k = range.first; k < range.one_past_last; k += 1){
Marker *new_marker = push_array(scratch, Marker, 1);
new_marker->pos = jumps.jumps[k].jump_pos;
new_marker->lean_right = false;
stored[k].list_line = jumps.jumps[k].list_line;
stored[k].list_colon_index = jumps.jumps[k].list_colon_index;
stored[k].is_sub_error = jumps.jumps[k].is_sub_error;
stored[k].jump_buffer_id = jumps.jumps[k].jump_buffer_id;
stored[k].index_into_marker_array = total_jump_count;
total_jump_count += 1;
}
}
scope_array[1] = buffer_get_dynamic_scope(app, target_buffer_id);
Dynamic_Scope scope = get_intersected_dynamic_scope(app, scope_array, ArrayCount(scope_array));
Managed_Object marker_handle = buffer_add_markers(app, target_buffer_id, jump_count, &scope);
Temp_Memory marker_temp = begin_temp_memory(part);
Marker *markers = push_array(part, Marker, jump_count);
for (int32_t j = 0; j < jump_count; j += 1){
markers[j].pos = jumps.jumps[j + range.first].jump_pos;
markers[j].lean_right = false;
}
buffer_set_markers(app, marker_handle, 0, jump_count, markers);
Managed_Object marker_handle = buffer_add_markers(app, target_buffer_id, total_jump_count, &scope);
buffer_set_markers(app, marker_handle, 0, total_jump_count, markers);
end_temp_memory(marker_temp);
int32_t line_details_mem_size = sizeof(Sticky_Jump_Line_Details)*jump_count;
Managed_Object memory = managed_memory_alloc(app, scope, line_details_mem_size);
Temp_Memory details_temp = begin_temp_memory(part);
Sticky_Jump_Line_Details *details = push_array(part, Sticky_Jump_Line_Details, jump_count);
for (int32_t j = 0; j < jump_count; j += 1){
details[j].list_line = jumps.jumps[j + range.first].list_line;
details[j].list_colon_index = jumps.jumps[j + range.first].list_colon_index;
details[j].is_sub_error = jumps.jumps[j + range.first].is_sub_error;
}
managed_memory_set(app, memory, 0, details, line_details_mem_size);
end_temp_memory(details_temp);
Managed_Object node_handle = managed_list_node_alloc(app, scope, sizeof(Sticky_Jump_Node_Header));
managed_list_node_insert(app, list_sentinel, node_handle, ListInsert_Back);
Sticky_Jump_Node_Header node_header = {0};
node_header.memory = memory;
node_header.markers = marker_handle;
node_header.count = jump_count;
managed_memory_set(app, node_handle, 0, &node_header, sizeof(node_header));
sticky_jump_marker_handle_loc = managed_variable_create_or_get_id(app, sticky_jump_marker_handle_var, 0);
managed_variable_set(app, scope, sticky_jump_marker_handle_loc, marker_handle);
}
Managed_Object stored_jump_array = managed_memory_alloc(app, scope_array[0], sizeof(Sticky_Jump_Stored)*jumps.count);
managed_memory_set(app, stored_jump_array, 0, sizeof(Sticky_Jump_Stored)*jumps.count, stored);
end_temp_memory(temp);
}
#else
static void
init_marker_list(Application_Links *app, Partition *part, General_Memory *general, Buffer_ID buffer_id,
Marker_List *list){
Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll);
Temp_Memory temp = begin_temp_memory(part);
Sticky_Jump_Array jumps = parse_buffer_to_jump_array(app, part, buffer);
Range_Array buffer_ranges = jump_array_mark_buffer_ranges(part, jumps);
list->dst_max = 64;
list->dst = gen_array(general, Sticky_Jump_Destination_Array, list->dst_max);
list->jump_max = 64;
list->jumps = gen_array(general, Sticky_Jump_Source, list->jump_max);
list->jump_array = stored_jump_array;
list->jump_count = jumps.count;
list->previous_size = buffer.size;
uint32_t prev_jump_count = 0;
for (int32_t i = 0; i < buffer_ranges.count; i += 1){
Range range = buffer_ranges.ranges[i];
Buffer_ID target_buffer_id = jumps.jumps[range.first].jump_buffer_id;
int32_t jump_count = range.one_past_last - range.first;
if (list->dst_count >= list->dst_max){
double_dst_max(general, list);
}
Buffer_Summary location_buffer = get_buffer(app, target_buffer_id, AccessAll);
Marker_Handle new_handle = buffer_add_markers(app, &location_buffer, jump_count,
sticky_jump_markers_cleanup, &list, sizeof(list));
list->dst[list->dst_count] = make_sticky_jump_destination_array(prev_jump_count, new_handle);
++list->dst_count;
prev_jump_count = list->jump_count;
Temp_Memory marker_temp = begin_temp_memory(part);
Marker *markers = push_array(part, Marker, jump_count);
for (int32_t j = 0; j < jump_count; j += 1){
markers[j].pos = jumps.jumps[j + range.first].jump_pos;
markers[j].lean_right = false;
}
buffer_set_markers(app, &location_buffer, new_handle, 0, jump_count, markers);
end_temp_memory(marker_temp);
for (int32_t j = range.first; j < range.one_past_last; j += 1){
if (list->jump_count >= list->jump_max){
double_jump_max(general, list);
}
uint32_t flags = 0;
if (jumps.jumps[j].is_sub_error){
flags |= JumpFlag_IsSubJump;
}
list->jumps[list->jump_count] = make_sticky_jump_source(jumps.jumps[j].list_line, flags);
++list->jump_count;
}
}
end_temp_memory(temp);
list->buffer_id = buffer_id;
}
#endif
static void
delete_marker_list(Marker_List_Node *node){
@ -244,8 +180,8 @@ delete_marker_list(Marker_List *list){
}
static Marker_List*
make_new_marker_list_for_buffer(General_Memory *general, int32_t buffer_id){
Marker_List_Node *new_node = gen_array(general, Marker_List_Node, 1);
make_new_marker_list_for_buffer(Heap *heap, int32_t buffer_id){
Marker_List_Node *new_node = heap_array(heap, Marker_List_Node, 1);
zdll_push_back(marker_list_first, marker_list_last, new_node);
new_node->buffer_id = buffer_id;
memset(&new_node->list, 0, sizeof(new_node->list));
@ -254,22 +190,20 @@ make_new_marker_list_for_buffer(General_Memory *general, int32_t buffer_id){
}
static Marker_List*
get_marker_list_for_buffer(General_Memory *general, int32_t buffer_id){
Marker_List *result = 0;
get_marker_list_for_buffer(Buffer_ID buffer_id){
for (Marker_List_Node *node = marker_list_first;
node != 0;
node = node->next){
if (buffer_id == node->buffer_id){
result = &node->list;
break;
return(&node->list);
}
}
return(result);
return(0);
}
static Marker_List*
get_or_make_list_for_buffer(Application_Links *app, Partition *part, General_Memory *general, int32_t buffer_id){
Marker_List *result = get_marker_list_for_buffer(general, buffer_id);
get_or_make_list_for_buffer(Application_Links *app, Partition *part, Heap *heap, int32_t buffer_id){
Marker_List *result = get_marker_list_for_buffer(buffer_id);
if (result != 0){
Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll);
// TODO(allen): When buffers get an "edit sequence number" use that instead.
@ -279,67 +213,118 @@ get_or_make_list_for_buffer(Application_Links *app, Partition *part, General_Mem
}
}
if (result == 0){
result = make_new_marker_list_for_buffer(general, buffer_id);
init_marker_list(app, part, general, buffer_id, result);
result = make_new_marker_list_for_buffer(heap, buffer_id);
init_marker_list(app, part, heap, buffer_id, result);
}
return(result);
}
static bool32
get_jump_from_list(Application_Links *app, Marker_List *list, int32_t index, ID_Pos_Jump_Location *location){
bool32 result = false;
if (index >= 0 && index < list->jump_count){
uint32_t handle_index = binary_search(&list->dst->first_jump_index, sizeof(*list->dst), list->dst_count, index);
Sticky_Jump_Destination_Array destinations = list->dst[handle_index];
uint32_t marker_index = index - destinations.first_jump_index;
Buffer_Summary buffer = get_buffer_by_marker_handle(app, destinations.handle, AccessAll);
if (buffer.exists){
Marker marker;
buffer_get_markers(app, &buffer, destinations.handle, marker_index, 1, &marker);
location->buffer_id = buffer.buffer_id;
location->pos = marker.pos;
result = true;
get_stored_jump_from_list(Application_Links *app, Marker_List *list, int32_t index,
Sticky_Jump_Stored *stored_out){
Sticky_Jump_Stored stored = {0};
if (managed_memory_get(app, list->jump_array, index*sizeof(stored), sizeof(stored), &stored)){
*stored_out = stored;
return(true);
}
return(false);
}
static Sticky_Jump_Stored*
get_all_stored_jumps_from_list(Application_Links *app, Partition *arena, Marker_List *list){
Temp_Memory restore_point = begin_temp_memory(arena);
Sticky_Jump_Stored *stored = push_array(arena, Sticky_Jump_Stored, list->jump_count);
if (stored != 0){
if (!managed_memory_get(app, list->jump_array, 0, sizeof(*stored)*list->jump_count, stored)){
stored = 0;
end_temp_memory(restore_point);
}
}
return(result);
return(stored);
}
static int32_t
get_index_exact_from_list(Marker_List *list, int32_t line){
int32_t result = -1;
uint32_t jump_index = binary_search(&list->jumps->line_number, sizeof(*list->jumps), list->jump_count, line);
if (list->jumps[jump_index].line_number == (uint32_t)line){
result = jump_index;
static bool32
get_jump_from_list(Application_Links *app, Marker_List *list, int32_t index, ID_Pos_Jump_Location *location){
Sticky_Jump_Stored stored = {0};
if (get_stored_jump_from_list(app, list, index, &stored)){
Buffer_ID target_buffer_id = stored.jump_buffer_id;
Dynamic_Scope scope_array[2] = {0};
scope_array[0] = buffer_get_dynamic_scope(app, list->buffer_id);
scope_array[1] = buffer_get_dynamic_scope(app, target_buffer_id);
Dynamic_Scope scope = get_intersected_dynamic_scope(app, scope_array, ArrayCount(scope_array));
sticky_jump_marker_handle_loc = managed_variable_create_or_get_id(app, sticky_jump_marker_handle_var, 0);
Managed_Object marker_array = 0;
if (managed_variable_get(app, scope, sticky_jump_marker_handle_loc, &marker_array)){
Marker marker = {0};
buffer_get_markers(app, marker_array, stored.index_into_marker_array, 1, &marker);
location->buffer_id = target_buffer_id;
location->pos = marker.pos;
return(true);
}
}
return(result);
return(false);
}
static int32_t
get_index_nearest_from_list(Marker_List *list, int32_t line){
int32_t result = binary_search(&list->jumps->line_number, sizeof(*list->jumps), list->jump_count, line);
return(result);
}
static int32_t
get_line_from_list(Marker_List *list, int32_t index){
get_line_from_list(Application_Links *app, Marker_List *list, int32_t index){
int32_t result = 0;
if (0 <= index && index < list->jump_count){
result = list->jumps[index].line_number;
Sticky_Jump_Stored stored = {0};
if (get_stored_jump_from_list(app, list, index, &stored)){
result = stored.list_line;
}
return(result);
}
static bool32
get_is_sub_error_from_list(Application_Links *app, Marker_List *list, int32_t index){
bool32 result = false;
Sticky_Jump_Stored stored = {0};
if (get_stored_jump_from_list(app, list, index, &stored)){
result = stored.is_sub_error;
}
return(result);
}
static int32_t
get_index_nearest_from_list(Application_Links *app, Partition *scratch, Marker_List *list, int32_t line){
int32_t result = -1;
Temp_Memory temp = begin_temp_memory(scratch);
Sticky_Jump_Stored *stored = get_all_stored_jumps_from_list(app, scratch, list);
if (stored != 0){
result = binary_search((uint32_t*)&stored->list_line, sizeof(*stored), list->jump_count, line);
}
end_temp_memory(temp);
return(result);
}
static int32_t
get_index_exact_from_list(Application_Links *app, Partition *scratch, Marker_List *list, int32_t line){
int32_t result = -1;
Temp_Memory temp = begin_temp_memory(scratch);
Sticky_Jump_Stored *stored = get_all_stored_jumps_from_list(app, scratch, list);
if (stored != 0){
int32_t index = binary_search((uint32_t*)&stored->list_line, sizeof(*stored), list->jump_count, line);
if (stored[index].list_line == line){
result = index;
}
}
end_temp_memory(temp);
return(result);
}
CUSTOM_COMMAND_SIG(goto_jump_at_cursor_sticky)
CUSTOM_DOC("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.")
{
General_Memory *general = &global_general;
Heap *heap = &global_heap;
Partition *part = &global_part;
Temp_Memory temp = begin_temp_memory(part);
View_Summary view = get_active_view(app, AccessProtected);
Marker_List *list = get_or_make_list_for_buffer(app, part, general, view.buffer_id);
Marker_List *list = get_or_make_list_for_buffer(app, part, heap, view.buffer_id);
int32_t list_index = get_index_exact_from_list(list, view.cursor.line);
int32_t list_index = get_index_exact_from_list(app, part, list, view.cursor.line);
if (list_index >= 0){
ID_Pos_Jump_Location location = {0};
@ -360,13 +345,13 @@ CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump loc
CUSTOM_COMMAND_SIG(goto_jump_at_cursor_same_panel_sticky)
CUSTOM_DOC("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.")
{
General_Memory *general = &global_general;
Heap *heap = &global_heap;
Partition *part = &global_part;
Temp_Memory temp = begin_temp_memory(part);
View_Summary view = get_active_view(app, AccessProtected);
Marker_List *list = get_or_make_list_for_buffer(app, part, general, view.buffer_id);
int32_t list_index = get_index_exact_from_list(list, view.cursor.line);
Marker_List *list = get_or_make_list_for_buffer(app, part, heap, view.buffer_id);
int32_t list_index = get_index_exact_from_list(app, part, list, view.cursor.line);
if (list_index >= 0){
ID_Pos_Jump_Location location = {0};
@ -423,13 +408,13 @@ goto_next_filtered_jump(Application_Links *app, Marker_List *list, View_Summary
if (skip_repeats && jump_is_repeat(prev_location, location)){
skip_this = true;
}
else if (skip_sub_errors && (list->jumps[list_index].flags & JumpFlag_IsSubJump)){
else if (skip_sub_errors && get_is_sub_error_from_list(app, list, list_index)){
skip_this = true;
}
if (!skip_this){
goto_jump_in_order(app, list, jump_view, location);
int32_t updated_line = get_line_from_list(list, list_index);
int32_t updated_line = get_line_from_list(app, list, list_index);
view_set_cursor(app, jump_view, seek_line_char(updated_line, 1), true);
break;
}
@ -440,12 +425,12 @@ goto_next_filtered_jump(Application_Links *app, Marker_List *list, View_Summary
}
static Locked_Jump_State
get_locked_jump_state(Application_Links *app, Partition *part, General_Memory *general){
get_locked_jump_state(Application_Links *app, Partition *part, Heap *heap){
Locked_Jump_State result = {0};
result.view = get_view_for_locked_jump_buffer(app);
if (result.view.exists){
result.list = get_or_make_list_for_buffer(app, part, general, result.view.buffer_id);
result.list_index = get_index_nearest_from_list(result.list, result.view.cursor.line);
result.list = get_or_make_list_for_buffer(app, part, heap, result.view.buffer_id);
result.list_index = get_index_nearest_from_list(app, part, result.list, result.view.cursor.line);
}
return(result);
}
@ -453,12 +438,12 @@ get_locked_jump_state(Application_Links *app, Partition *part, General_Memory *g
CUSTOM_COMMAND_SIG(goto_next_jump_sticky)
CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.")
{
General_Memory *general = &global_general;
Heap *heap = &global_heap;
Partition *part = &global_part;
Locked_Jump_State jump_state = get_locked_jump_state(app, part, general);
Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap);
if (jump_state.view.exists){
int32_t line = get_line_from_list(jump_state.list, jump_state.list_index);
int32_t line = get_line_from_list(app, jump_state.list, jump_state.list_index);
if (line <= jump_state.view.cursor.line){
++jump_state.list_index;
}
@ -468,10 +453,10 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th
CUSTOM_COMMAND_SIG(goto_prev_jump_sticky)
CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations."){
General_Memory *general = &global_general;
Heap *heap = &global_heap;
Partition *part = &global_part;
Locked_Jump_State jump_state = get_locked_jump_state(app, part, general);
Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap);
if (jump_state.view.exists){
if (jump_state.list_index > 0){
--jump_state.list_index;
@ -483,12 +468,12 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th
CUSTOM_COMMAND_SIG(goto_next_jump_no_skips_sticky)
CUSTOM_DOC("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.")
{
General_Memory *general = &global_general;
Heap *heap = &global_heap;
Partition *part = &global_part;
Locked_Jump_State jump_state = get_locked_jump_state(app, part, general);
Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap);
if (jump_state.view.exists){
int32_t line = get_line_from_list(jump_state.list, jump_state.list_index);
int32_t line = get_line_from_list(app, jump_state.list, jump_state.list_index);
if (line <= jump_state.view.cursor.line){
++jump_state.list_index;
}
@ -499,10 +484,10 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th
CUSTOM_COMMAND_SIG(goto_prev_jump_no_skips_sticky)
CUSTOM_DOC("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.")
{
General_Memory *general = &global_general;
Heap *heap = &global_heap;
Partition *part = &global_part;
Locked_Jump_State jump_state = get_locked_jump_state(app, part, general);
Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap);
if (jump_state.view.exists){
if (jump_state.list_index > 0){
--jump_state.list_index;
@ -514,16 +499,16 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th
CUSTOM_COMMAND_SIG(goto_first_jump_sticky)
CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.")
{
General_Memory *general = &global_general;
Heap *heap = &global_heap;
Partition *part = &global_part;
Locked_Jump_State jump_state = get_locked_jump_state(app, part, general);
Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap);
if (jump_state.view.exists){
int32_t list_index = 0;
ID_Pos_Jump_Location location = {0};
if (get_jump_from_list(app, jump_state.list, list_index, &location)){
goto_jump_in_order(app, jump_state.list, &jump_state.view, location);
int32_t updated_line = get_line_from_list(jump_state.list, list_index);
int32_t updated_line = get_line_from_list(app, jump_state.list, list_index);
view_set_cursor(app, &jump_state.view, seek_line_char(updated_line, 1), true);
}
}
@ -532,10 +517,10 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th
CUSTOM_COMMAND_SIG(goto_first_jump_same_panel_sticky)
CUSTOM_DOC("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.")
{
General_Memory *general = &global_general;
Heap *heap = &global_heap;
Partition *part = &global_part;
Locked_Jump_State jump_state = get_locked_jump_state(app, part, general);
Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap);
if (jump_state.view.exists){
int32_t list_index = 0;
ID_Pos_Jump_Location location = {0};
@ -588,10 +573,8 @@ CUSTOM_DOC("If the buffer in the active view is writable, inserts a character, o
OPEN_FILE_HOOK_SIG(default_end_file);
OPEN_FILE_HOOK_SIG(end_file_close_jump_list){
General_Memory *general = &global_general;
Marker_List *list = get_marker_list_for_buffer(general, buffer_id);
Marker_List *list = get_marker_list_for_buffer(buffer_id);
if (list != 0){
free_marker_list(general, *list);
delete_marker_list(list);
}
default_end_file(app, buffer_id);

View File

@ -7,12 +7,6 @@
#if !defined(FCODER_JUMP_STICKY_H)
#define FCODER_JUMP_STICKY_H
struct Sticky_Jump_Line_Details{
int32_t list_line;
int32_t list_colon_index;
bool32 is_sub_error;
};
struct Sticky_Jump{
int32_t list_line;
int32_t list_colon_index;
@ -21,6 +15,14 @@ struct Sticky_Jump{
int32_t jump_pos;
};
struct Sticky_Jump_Stored{
int32_t list_line;
int32_t list_colon_index;
bool32 is_sub_error;
Buffer_ID jump_buffer_id;
int32_t index_into_marker_array;
};
struct Sticky_Jump_Array{
struct Sticky_Jump *jumps;
int32_t count;
@ -38,14 +40,17 @@ enum Jump_Location_Flag{
};
struct Marker_List{
Managed_Object jump_array;
int32_t jump_count;
int32_t previous_size;
Buffer_ID buffer_id;
};
struct Marker_List_Node{
Marker_List_Node *next;
Marker_List_Node *prev;
Marker_List list;
int32_t buffer_id;
Buffer_ID buffer_id;
};
struct Locked_Jump_State{

109
4coder_lib/4coder_arena.cpp Normal file
View File

@ -0,0 +1,109 @@
/*
4coder_arena.cpp - Preversioning
no warranty implied; use at your own risk
This software is in the public domain. Where that dedication is not
recognized, you are granted a perpetual, irrevocable license to copy,
distribute, and modify this file as you see fit.
*/
// TOP
inline Partition
make_part(void *memory, i32_4tech size){
Partition partition = {0};
partition.base = (char*)memory;
partition.pos = 0;
partition.max = size;
return partition;
}
inline void*
partition_allocate(Partition *data, i32_4tech size){
void *ret = 0;
if (size < 0){
size = 0;
}
if (data->pos + size <= data->max){
ret = data->base + data->pos;
data->pos += size;
}
return(ret);
}
inline void
partition_reduce(Partition *data, i32_4tech size){
if (size > 0 && size <= data->pos){
data->pos -= size;
}
}
inline void*
partition_align(Partition *data, u32_4tech boundary){
--boundary;
data->pos = (data->pos + boundary) & (~boundary);
return(data->base + data->pos);
}
inline void*
partition_current(Partition *data){
return(data->base + data->pos);
}
inline i32_4tech
partition_remaining(Partition *data){
return(data->max - data->pos);
}
inline Partition
partition_sub_part(Partition *data, i32_4tech size){
Partition result = {};
void *d = partition_allocate(data, size);
if (d != 0){
result = make_part(d, size);
}
return(result);
}
#define push_struct(part, T) (T*)partition_allocate(part, sizeof(T))
#define push_array(part, T, size) (T*)partition_allocate(part, sizeof(T)*(size))
#define push_block(part, size) partition_allocate(part, size)
#define push_align(part, b) partition_align(part, b)
inline Temp_Memory
begin_temp_memory(Partition *data){
Temp_Memory result;
result.handle = data;
result.pos = data->pos;
return(result);
}
inline void
end_temp_memory(Temp_Memory temp){
((Partition*)temp.handle)->pos = temp.pos;
}
inline Tail_Temp_Partition
begin_tail_part(Partition *data, i32_4tech size){
Tail_Temp_Partition result = {0};
if (data->pos + size <= data->max){
result.handle = data;
result.old_max = data->max;
data->max -= size;
result.part = make_part(data->base + data->max, size);
}
return(result);
}
inline void
end_tail_part(Tail_Temp_Partition temp){
if (temp.handle){
Partition *part = (Partition*)temp.handle;
part->max = temp.old_max;
}
}
#define reset_temp_memory end_temp_memory
// BOTTOM

67
4coder_lib/4coder_arena.h Normal file
View File

@ -0,0 +1,67 @@
/*
4coder_arena.h - Preversioning
no warranty implied; use at your own risk
This software is in the public domain. Where that dedication is not
recognized, you are granted a perpetual, irrevocable license to copy,
distribute, and modify this file as you see fit.
*/
// TOP
#if !defined(FCODER_ARENA_H)
#define FCODER_ARENA_H
// 4tech_standard_preamble.h
#if !defined(FTECH_INTEGERS)
#define FTECH_INTEGERS
#include <stdint.h>
typedef int8_t i8_4tech;
typedef int16_t i16_4tech;
typedef int32_t i32_4tech;
typedef int64_t i64_4tech;
typedef uint8_t u8_4tech;
typedef uint16_t u16_4tech;
typedef uint32_t u32_4tech;
typedef uint64_t u64_4tech;
#if defined(FTECH_32_BIT)
typedef u32_4tech umem_4tech;
#else
typedef u64_4tech umem_4tech;
#endif
typedef float f32_4tech;
typedef double f64_4tech;
typedef int8_t b8_4tech;
typedef int32_t b32_4tech;
#endif
#if !defined(Assert)
# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0)
#endif
// standard preamble end
struct Partition{
char *base;
i32_4tech pos;
i32_4tech max;
};
struct Temp_Memory{
void *handle;
i32_4tech pos;
};
struct Tail_Temp_Partition{
Partition part;
void *handle;
i32_4tech old_max;
};
#endif
// BOTTOM

View File

@ -0,0 +1,93 @@
/*
4coder_heap.cpp - Preversioning
no warranty implied; use at your own risk
This software is in the public domain. Where that dedication is not
recognized, you are granted a perpetual, irrevocable license to copy,
distribute, and modify this file as you see fit.
*/
// TOP
#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))
#define heap__remove(n) ((n)->next->prev=(n)->prev,(n)->prev->next=(n)->next)
static void
heap_init(Heap *heap){
heap__sent_init(&heap->in_order);
heap__sent_init(&heap->free_nodes);
}
static void
heap_extend(Heap *heap, void *memory, i32_4tech size){
if (size >= sizeof(Heap_Node)){
Heap_Node *new_node = (Heap_Node*)memory;
heap__insert_prev(&heap->in_order, &new_node->order);
heap__insert_next(&heap->free_nodes, &new_node->alloc);
new_node->size = size - sizeof(*new_node);
}
}
static void*
heap__reserve_chunk(Heap_Node *node, i32_4tech size){
u8_4tech *ptr = (u8_4tech*)(node + 1);
i32_4tech left_over_size = node->size - size;
if (left_over_size > sizeof(*node)){
i32_4tech new_node_size = left_over_size - sizeof(*node);
Heap_Node *new_node = (Heap_Node*)(ptr + size);
heap__insert_next(&node->order, &new_node->order);
heap__insert_next(&node->alloc, &new_node->alloc);
new_node->size = new_node_size;
heap__remove(&node->alloc);
node->alloc.next = 0;
node->alloc.prev = 0;
node->size = size;
}
return(ptr);
}
static void*
heap_allocate(Heap *heap, i32_4tech size){
i32_4tech aligned_size = (size + sizeof(Heap_Node) - 1);
aligned_size = aligned_size - (aligned_size%sizeof(Heap_Node));
for (Heap_Basic_Node *n = heap->free_nodes.next;
n != &heap->free_nodes;
n = n->next){
Heap_Node *node = CastFromMember(Heap_Node, alloc, n);
if (node->size >= aligned_size){
return(heap__reserve_chunk(node, aligned_size));
}
}
return(0);
}
static void
heap__merge(Heap *heap, Heap_Node *l, Heap_Node *r){
if (&l->order != &heap->in_order && &r->order != &heap->in_order &&
l->alloc.next != 0 && l->alloc.prev != 0 &&
r->alloc.next != 0 && r->alloc.prev != 0){
u8_4tech *ptr = (u8_4tech*)(l + 1) + l->size;
if (PtrDif(ptr, r) == 0){
heap__remove(&r->order);
heap__remove(&r->alloc);
heap__remove(&l->alloc);
l->size += r->size + sizeof(*r);
heap__insert_next(&heap->free_nodes, &l->alloc);
}
}
}
static void
heap_free(Heap *heap, void *memory){
Heap_Node *node = ((Heap_Node*)memory) - 1;
heap__insert_next(&heap->free_nodes, &node->alloc);
heap__merge(heap, node, CastFromMember(Heap_Node, order, node->order.next));
heap__merge(heap, CastFromMember(Heap_Node, order, node->order.prev), node);
}
#define heap_array(g, T, size) (T*)heap_allocate(g, sizeof(T)*(size))
// BOTTOM

91
4coder_lib/4coder_heap.h Normal file
View File

@ -0,0 +1,91 @@
/*
4coder_heap.h - Preversioning
no warranty implied; use at your own risk
This software is in the public domain. Where that dedication is not
recognized, you are granted a perpetual, irrevocable license to copy,
distribute, and modify this file as you see fit.
*/
// TOP
#if !defined(FCODER_HEAP_H)
#define FCODER_HEAP_H
// 4tech_standard_preamble.h
#if !defined(FTECH_INTEGERS)
#define FTECH_INTEGERS
#include <stdint.h>
typedef int8_t i8_4tech;
typedef int16_t i16_4tech;
typedef int32_t i32_4tech;
typedef int64_t i64_4tech;
typedef uint8_t u8_4tech;
typedef uint16_t u16_4tech;
typedef uint32_t u32_4tech;
typedef uint64_t u64_4tech;
#if defined(FTECH_32_BIT)
typedef u32_4tech umem_4tech;
#else
typedef u64_4tech umem_4tech;
#endif
typedef float f32_4tech;
typedef double f64_4tech;
typedef int8_t b8_4tech;
typedef int32_t b32_4tech;
#endif
#if !defined(Assert)
# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0)
#endif
#if !defined(Member)
# define Member(T, m) (((T*)0)->m)
#endif
#if !defined(PtrDif)
#define PtrDif(a,b) ((uint8_t*)(a) - (uint8_t*)(b))
#endif
#if !defined(PtrAsInt)
#define PtrAsInt(a) PtrDif(a,0)
#endif
#if !defined(OffsetOfMember)
#define OffsetOfMember(S,m) PtrAsInt(&Member(S,m))
#endif
#if !defined(CastFromMember)
#define CastFromMember(S,m,ptr) (S*)( (uint8_t*)(ptr) - OffsetOfMember(S,m) )
#endif
// standard preamble end
struct Heap_Basic_Node{
Heap_Basic_Node *next;
Heap_Basic_Node *prev;
};
struct Heap_Node{
union{
struct{
Heap_Basic_Node order;
Heap_Basic_Node alloc;
i32_4tech size;
};
u8_4tech force_size__[64];
};
};
struct Heap{
Heap_Basic_Node in_order;
Heap_Basic_Node free_nodes;
};
#endif
// BOTTOM

View File

@ -1,375 +0,0 @@
/*
4coder_mem.h - Preversioning
no warranty implied; use at your own risk
This software is in the public domain. Where that dedication is not
recognized, you are granted a perpetual, irrevocable license to copy,
distribute, and modify this file as you see fit.
*/
// TOP
#if !defined(FCODER_MEM_H)
#define FCODER_MEM_H
// 4tech_standard_preamble.h
#if !defined(FTECH_INTEGERS)
#define FTECH_INTEGERS
#include <stdint.h>
typedef int8_t i8_4tech;
typedef int16_t i16_4tech;
typedef int32_t i32_4tech;
typedef int64_t i64_4tech;
typedef uint8_t u8_4tech;
typedef uint16_t u16_4tech;
typedef uint32_t u32_4tech;
typedef uint64_t u64_4tech;
#if defined(FTECH_32_BIT)
typedef u32_4tech umem_4tech;
#else
typedef u64_4tech umem_4tech;
#endif
typedef float f32_4tech;
typedef double f64_4tech;
typedef int8_t b8_4tech;
typedef int32_t b32_4tech;
#endif
#if !defined(Assert)
# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0)
#endif
// standard preamble end
#include <string.h>
struct Partition{
char *base;
i32_4tech pos;
i32_4tech max;
};
struct Temp_Memory{
void *handle;
i32_4tech pos;
};
struct Tail_Temp_Partition{
Partition part;
void *handle;
i32_4tech old_max;
};
inline Partition
make_part(void *memory, i32_4tech size){
Partition partition = {0};
partition.base = (char*)memory;
partition.pos = 0;
partition.max = size;
return partition;
}
inline void*
partition_allocate(Partition *data, i32_4tech size){
void *ret = 0;
if (size < 0){
size = 0;
}
if (data->pos + size <= data->max){
ret = data->base + data->pos;
data->pos += size;
}
return(ret);
}
inline void
partition_reduce(Partition *data, i32_4tech size){
if (size > 0 && size <= data->pos){
data->pos -= size;
}
}
inline void*
partition_align(Partition *data, u32_4tech boundary){
--boundary;
data->pos = (data->pos + boundary) & (~boundary);
return(data->base + data->pos);
}
inline void*
partition_current(Partition *data){
return(data->base + data->pos);
}
inline i32_4tech
partition_remaining(Partition *data){
return(data->max - data->pos);
}
inline Partition
partition_sub_part(Partition *data, i32_4tech size){
Partition result = {};
void *d = partition_allocate(data, size);
if (d != 0){
result = make_part(d, size);
}
return(result);
}
#define push_struct(part, T) (T*)partition_allocate(part, sizeof(T))
#define push_array(part, T, size) (T*)partition_allocate(part, sizeof(T)*(size))
#define push_block(part, size) partition_allocate(part, size)
#define push_align(part, b) partition_align(part, b)
inline Temp_Memory
begin_temp_memory(Partition *data){
Temp_Memory result;
result.handle = data;
result.pos = data->pos;
return(result);
}
inline void
end_temp_memory(Temp_Memory temp){
((Partition*)temp.handle)->pos = temp.pos;
}
inline Tail_Temp_Partition
begin_tail_part(Partition *data, i32_4tech size){
Tail_Temp_Partition result = {0};
if (data->pos + size <= data->max){
result.handle = data;
result.old_max = data->max;
data->max -= size;
result.part = make_part(data->base + data->max, size);
}
return(result);
}
inline void
end_tail_part(Tail_Temp_Partition temp){
if (temp.handle){
Partition *part = (Partition*)temp.handle;
part->max = temp.old_max;
}
}
#define reset_temp_memory end_temp_memory
/*
NOTE(allen):
This is a very week general purpose allocator system.
It should only be used for infrequent large allocations (4K+).
*/
enum{
MEM_BUBBLE_FLAG_INIT = 0x0,
MEM_BUBBLE_USED = 0x1,
};
struct Bubble{
Bubble *prev;
Bubble *next;
Bubble *prev2;
Bubble *next2;
i32_4tech size;
u32_4tech flags;
u32_4tech _unused_[4];
};
struct General_Memory{
Bubble sentinel;
Bubble free_sentinel;
Bubble used_sentinel;
};
struct Mem_Options{
Partition part;
General_Memory general;
};
inline void
insert_bubble(Bubble *prev, Bubble *bubble){
bubble->prev = prev;
bubble->next = prev->next;
bubble->prev->next = bubble;
bubble->next->prev = bubble;
}
inline void
remove_bubble(Bubble *bubble){
bubble->prev->next = bubble->next;
bubble->next->prev = bubble->prev;
}
inline void
insert_bubble2(Bubble *prev, Bubble *bubble){
bubble->prev2 = prev;
bubble->next2 = prev->next2;
bubble->prev2->next2 = bubble;
bubble->next2->prev2 = bubble;
}
inline void
remove_bubble2(Bubble *bubble){
bubble->prev2->next2 = bubble->next2;
bubble->next2->prev2 = bubble->prev2;
}
static void
general_sentinel_init(Bubble *bubble){
bubble->prev = bubble;
bubble->next = bubble;
bubble->prev2 = bubble;
bubble->next2 = bubble;
bubble->flags = MEM_BUBBLE_USED;
bubble->size = 0;
}
#define BUBBLE_MIN_SIZE 1024
static void
general_memory_attempt_split(General_Memory *general, Bubble *bubble, i32_4tech wanted_size){
i32_4tech remaining_size = bubble->size - wanted_size;
if (remaining_size >= BUBBLE_MIN_SIZE){
bubble->size = wanted_size;
Bubble *new_bubble = (Bubble*)((char*)(bubble + 1) + wanted_size);
new_bubble->flags = (u32_4tech)MEM_BUBBLE_FLAG_INIT;
new_bubble->size = remaining_size - sizeof(Bubble);
insert_bubble(bubble, new_bubble);
insert_bubble2(&general->free_sentinel, new_bubble);
}
}
inline void
general_memory_do_merge(Bubble *left, Bubble *right){
left->size += sizeof(Bubble) + right->size;
remove_bubble(right);
remove_bubble2(right);
}
inline void
general_memory_attempt_merge(Bubble *left, Bubble *right){
if (!(left->flags & MEM_BUBBLE_USED) && !(right->flags & MEM_BUBBLE_USED)){
general_memory_do_merge(left, right);
}
}
// NOTE(allen): public procedures
static void
general_memory_open(General_Memory *general, void *memory, i32_4tech size){
general_sentinel_init(&general->sentinel);
general_sentinel_init(&general->free_sentinel);
general_sentinel_init(&general->used_sentinel);
Bubble *first = (Bubble*)memory;
first->flags = (u32_4tech)MEM_BUBBLE_FLAG_INIT;
first->size = size - sizeof(Bubble);
insert_bubble(&general->sentinel, first);
insert_bubble2(&general->free_sentinel, first);
}
#if defined(Assert)
static i32_4tech
general_memory_check(General_Memory *general){
Bubble *sentinel = &general->sentinel;
for (Bubble *bubble = sentinel->next;
bubble != sentinel;
bubble = bubble->next){
Assert(bubble);
Bubble *next = bubble->next;
Assert(bubble == next->prev);
if (next != sentinel && bubble->prev != sentinel){
Assert(bubble->next > bubble);
Assert(bubble > bubble->prev);
char *end_ptr = (char*)(bubble + 1) + bubble->size;
char *next_ptr = (char*)next;
(void)(end_ptr);
(void)(next_ptr);
Assert(end_ptr == next_ptr);
}
}
return(1);
}
#else
static i32_4tech
general_memory_check(General_Memory *general){}
#endif
static void*
general_memory_allocate(General_Memory *general, i32_4tech size){
void *result = 0;
if (size < BUBBLE_MIN_SIZE) size = BUBBLE_MIN_SIZE;
for (Bubble *bubble = general->free_sentinel.next2;
bubble != &general->free_sentinel;
bubble = bubble->next2){
if (!(bubble->flags & MEM_BUBBLE_USED)){
if (bubble->size >= size){
result = bubble + 1;
bubble->flags |= MEM_BUBBLE_USED;
remove_bubble2(bubble);
insert_bubble2(&general->used_sentinel, bubble);
general_memory_attempt_split(general, bubble, size);
break;
}
}
}
return(result);
}
static void
general_memory_free(General_Memory *general, void *memory){
Bubble *bubble = ((Bubble*)memory) - 1;
bubble->flags = 0;
remove_bubble2(bubble);
insert_bubble2(&general->free_sentinel, bubble);
Bubble *prev, *next;
prev = bubble->prev;
next = bubble->next;
general_memory_attempt_merge(bubble, next);
general_memory_attempt_merge(prev, bubble);
}
static void*
general_memory_reallocate(General_Memory *general, void *old, i32_4tech old_size, i32_4tech size){
void *result = old;
Bubble *bubble = ((Bubble*)old) - 1;
i32_4tech additional_space = size - bubble->size;
if (additional_space > 0){
Bubble *next = bubble->next;
if (!(next->flags & MEM_BUBBLE_USED) && next->size + (i32_4tech)sizeof(Bubble) >= additional_space){
general_memory_do_merge(bubble, next);
general_memory_attempt_split(general, bubble, size);
}
else{
result = general_memory_allocate(general, size);
if (old_size) memcpy(result, old, old_size);
general_memory_free(general, old);
}
}
return(result);
}
inline void*
general_memory_reallocate_nocopy(General_Memory *general, void *old, i32_4tech size){
void *result = general_memory_reallocate(general, old, 0, size);
return(result);
}
#define gen_struct(g, T) (T*)general_memory_allocate(g, sizeof(T), 0)
#define gen_array(g, T, size) (T*)general_memory_allocate(g, sizeof(T)*(size))
#define gen_block(g, size) general_memory_open(g, size, 0)
#define gen_realloc_array(g, T, old, old_size, size)\
(T*)general_memory_reallocate(g, old, old_size*sizeof(T), size*sizeof(T))
#endif
// BOTTOM

View File

@ -18,7 +18,7 @@ CUSTOM_COMMAND_SIG(lister__activate)
CUSTOM_DOC("A lister mode command that activates the list's action on the highlighted item.")
{
Partition *scratch = &global_part;
General_Memory *general = &global_general;
Heap *heap = &global_heap;
View_Summary view = get_active_view(app, AccessAll);
Lister_State *state = view_get_lister_state(&view);
if (state->initialized){
@ -26,8 +26,7 @@ CUSTOM_DOC("A lister mode command that activates the list's action on the highli
if (0 <= state->raw_item_index && state->raw_item_index < state->lister.options.count){
user_data = lister_get_user_data(&state->lister, state->raw_item_index);
}
lister_call_activate_handler(app, scratch, general, &view,
state, user_data, false);
lister_call_activate_handler(app, scratch, heap, &view, state, user_data, false);
}
}
@ -102,13 +101,13 @@ CUSTOM_COMMAND_SIG(lister__mouse_release)
CUSTOM_DOC("A lister mode command that ends a click interaction with a list item under the mouse, possibly activating it.")
{
Partition *scratch = &global_part;
General_Memory *general = &global_general;
Heap *heap = &global_heap;
View_Summary view = get_active_view(app, AccessAll);
Lister_State *state = view_get_lister_state(&view);
if (state->initialized && state->hot_user_data != 0){
UI_Item clicked = lister_get_clicked_item(app, &view, scratch);
if (state->hot_user_data == clicked.user_data){
lister_call_activate_handler(app, scratch, general, &view,
lister_call_activate_handler(app, scratch, heap, &view,
state, clicked.user_data, true);
}
}
@ -257,7 +256,7 @@ CUSTOM_COMMAND_SIG(lister__write_character__fixed_list)
CUSTOM_DOC("A lister mode command that handles input for the fixed sure to kill list.")
{
Partition *scratch = &global_part;
General_Memory *general = &global_general;
Heap *heap = &global_heap;
View_Summary view = get_active_view(app, AccessAll);
Lister_State *state = view_get_lister_state(&view);
if (state->initialized){
@ -278,7 +277,7 @@ CUSTOM_DOC("A lister mode command that handles input for the fixed sure to kill
}
}
if (did_shortcut_key){
lister_call_activate_handler(app, scratch, general,
lister_call_activate_handler(app, scratch, heap,
&view, state,
user_data, false);
}
@ -314,11 +313,11 @@ begin_integrated_lister__with_refresh_handler(Application_Links *app, char *quer
View_Summary *view){
if (handlers.refresh != 0){
Partition *scratch = &global_part;
General_Memory *general = &global_general;
Heap *heap = &global_heap;
view_start_ui_mode(app, view);
view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map);
Lister_State *state = view_get_lister_state(view);
init_lister_state(state, general);
init_lister_state(state, heap);
lister_first_init(&state->lister);
lister_set_query_string(&state->lister, query_string);
state->lister.handlers = handlers;
@ -342,11 +341,11 @@ begin_integrated_lister__with_fixed_options(Application_Links *app, char *query_
Lister_Fixed_Option *options, int32_t option_count,
View_Summary *view){
Partition *scratch = &global_part;
General_Memory *general = &global_general;
Heap *heap = &global_heap;
view_start_ui_mode(app, view);
view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map);
Lister_State *state = view_get_lister_state(view);
init_lister_state(state, general);
init_lister_state(state, heap);
lister_first_init(&state->lister);
for (int32_t i = 0; i < option_count; i += 1){
char *shortcut_chars = options[i].shortcut_chars;
@ -384,11 +383,11 @@ begin_integrated_lister__ui_list(Application_Links *app, char *query_string,
Lister_UI_Option *options, int32_t option_count,
View_Summary *view){
Partition *scratch = &global_part;
General_Memory *general = &global_general;
Heap *heap = &global_heap;
view_start_ui_mode(app, view);
view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map);
Lister_State *state = view_get_lister_state(view);
init_lister_state(state, general);
init_lister_state(state, heap);
lister_first_init(&state->lister);
state->lister.theme_list = true;
for (int32_t i = 0; i < option_count; i += 1){

View File

@ -8,7 +8,6 @@
#include "4coder_file.h"
#include "4coder_lib/4coder_mem.h"
#include "4coder_lib/4cpp_lexer.h"
#include <stdio.h>

View File

@ -7,8 +7,6 @@
#if !defined(FCODER_PROJECT_COMMANDS_H)
#define FCODER_PROJECT_COMMANDS_H
#include "4coder_lib/4coder_mem.h"
enum{
OpenAllFilesFlag_Recursive = 1,
};

View File

@ -10,7 +10,7 @@ and list all locations.
//
static void
search_key_alloc(General_Memory *general, Search_Key *key, int32_t *size, int32_t count){
search_key_alloc(Heap *heap, Search_Key *key, int32_t *size, int32_t count){
if (count > ArrayCount(key->words)){
count = ArrayCount(key->words);
}
@ -24,14 +24,15 @@ search_key_alloc(General_Memory *general, Search_Key *key, int32_t *size, int32_
}
}
int32_t max_base_size = total_size*2;
if (key->base == 0){
key->base = (char*)general_memory_allocate(general, max_base_size);
int32_t max_base_size = total_size*2;
key->base = heap_array(heap, char, max_base_size);
key->base_size = max_base_size;
}
else if (key->base_size < total_size){
key->base = (char*)general_memory_reallocate_nocopy(general, key->base, max_base_size);
int32_t max_base_size = total_size*2;
heap_free(heap, key->base);
key->base = heap_array(heap, char, max_base_size);
key->base_size = max_base_size;
}
@ -55,52 +56,54 @@ search_iter_init(Search_Iter *iter, Search_Key key){
}
static void
search_set_init(General_Memory *general, Search_Set *set, int32_t range_count){
int32_t max = range_count*2;
search_set_init(Heap *heap, Search_Set *set, int32_t range_count){
if (set->ranges == 0){
set->ranges = (Search_Range*)general_memory_allocate(general, sizeof(Search_Range)*max);
int32_t max = range_count*2;
set->ranges = heap_array(heap, Search_Range, max);
set->max = max;
}
else if (set->max < range_count){
set->ranges = (Search_Range*)general_memory_reallocate_nocopy(
general, set->ranges, sizeof(Search_Range)*max);
int32_t max = range_count*2;
heap_free(heap, set->ranges);
set->ranges = heap_array(heap, Search_Range, max);
set->max = max;
}
set->count = range_count;
}
static void
search_hits_table_alloc(General_Memory *general, Table *hits, int32_t table_size){
search_hits_table_alloc(Heap *heap, Table *hits, int32_t table_size){
void *mem = 0;
int32_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String));
if (hits->hash_array == 0){
mem = general_memory_allocate(general, mem_size);
mem = heap_allocate(heap, mem_size);
}
else{
mem = general_memory_reallocate_nocopy(general, hits->hash_array, mem_size);
heap_free(heap, hits->hash_array);
mem = heap_allocate(heap, mem_size);
}
table_init_memory(hits, mem, table_size, sizeof(Offset_String));
}
static void
search_hits_init(General_Memory *general, Table *hits, String_Space *str, int32_t table_size, int32_t str_size){
search_hits_init(Heap *heap, Table *hits, String_Space *str, int32_t table_size, int32_t str_size){
if (hits->hash_array == 0){
search_hits_table_alloc(general, hits, table_size);
search_hits_table_alloc(heap, hits, table_size);
}
else{
int32_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String));
void *mem = general_memory_reallocate_nocopy(general, hits->hash_array, mem_size);
heap_free(heap, hits->hash_array);
void *mem = heap_allocate(heap, mem_size);
table_init_memory(hits, mem, table_size, sizeof(Offset_String));
}
if (str->space == 0){
str->space = (char*)general_memory_allocate(general, str_size);
str->space = heap_array(heap, char, str_size);
str->max = str_size;
}
else if (str->max < str_size){
str->space = (char*)general_memory_reallocate_nocopy(general, str->space, str_size);
heap_free(heap, str->space);
str->space = heap_array(heap, char, str_size);
str->max = str_size;
}
@ -113,7 +116,7 @@ search_hits_init(General_Memory *general, Table *hits, String_Space *str, int32_
//
static int32_t
search_hit_add(General_Memory *general, Table *hits, String_Space *space, char *str, int32_t len){
search_hit_add(Heap *heap, Table *hits, String_Space *space, char *str, int32_t len){
int32_t result = false;
Assert(len != 0);
@ -124,7 +127,10 @@ search_hit_add(General_Memory *general, Table *hits, String_Space *space, char *
if (new_size < space->max + len){
new_size = space->max + len;
}
space->space = (char*)general_memory_reallocate(general, space->space, space->new_pos, new_size);
char *new_space = heap_array(heap, char, new_size);
memcpy(new_space, space->space, space->new_pos);
heap_free(heap, space->space);
space->space = new_space;
ostring = strspace_append(space, str, len);
}
@ -132,10 +138,10 @@ search_hit_add(General_Memory *general, Table *hits, String_Space *space, char *
if (table_at_capacity(hits)){
Table new_hits = {0};
search_hits_table_alloc(general, &new_hits, hits->max*2);
search_hits_table_alloc(heap, &new_hits, hits->max*2);
table_clear(&new_hits);
table_rehash(hits, &new_hits, space->space, tbl_offset_string_hash, tbl_offset_string_compare);
general_memory_free(general, hits->hash_array);
heap_free(heap, hits->hash_array);
*hits = new_hits;
}
@ -478,7 +484,7 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){
//
static void
initialize_generic_search_all_buffers(Application_Links *app, General_Memory *general, String *strings, int32_t count, Search_Range_Flag match_flags, int32_t *skip_buffers, int32_t skip_buffer_count, Search_Set *set, Search_Iter *iter){
initialize_generic_search_all_buffers(Application_Links *app, Heap *heap, String *strings, int32_t count, Search_Range_Flag match_flags, int32_t *skip_buffers, int32_t skip_buffer_count, Search_Set *set, Search_Iter *iter){
memset(set, 0, sizeof(*set));
memset(iter, 0, sizeof(*iter));
@ -494,7 +500,7 @@ initialize_generic_search_all_buffers(Application_Links *app, General_Memory *ge
}
// TODO(allen): Why on earth am I allocating these separately in this case? Upgrade to just use the string array on the stack!
search_key_alloc(general, &key, sizes, count);
search_key_alloc(heap, &key, sizes, count);
for (int32_t i = 0; i < count; ++i){
copy(&key.words[i], strings[i]);
}
@ -502,7 +508,7 @@ initialize_generic_search_all_buffers(Application_Links *app, General_Memory *ge
search_iter_init(iter, key);
int32_t buffer_count = get_buffer_count(app);
search_set_init(general, set, buffer_count);
search_set_init(heap, set, buffer_count);
Search_Range *ranges = set->ranges;
@ -613,7 +619,7 @@ buffered_print_match_jump_line(Application_Links *app, Partition *part, Temp_Mem
}
static void
list__parameters(Application_Links *app, General_Memory *general, Partition *scratch,
list__parameters(Application_Links *app, Heap *heap, Partition *scratch,
String *strings, int32_t count, Search_Range_Flag match_flags){
// Open the search buffer
String search_name = make_lit_string("*search*");
@ -632,7 +638,7 @@ list__parameters(Application_Links *app, General_Memory *general, Partition *scr
// Initialize a generic search all buffers
Search_Set set = {0};
Search_Iter iter = {0};
initialize_generic_search_all_buffers(app, general, strings, count, match_flags, &search_buffer.buffer_id, 1, &set, &iter);
initialize_generic_search_all_buffers(app, heap, strings, count, match_flags, &search_buffer.buffer_id, 1, &set, &iter);
// List all locations into search buffer
Temp_Memory all_temp = begin_temp_memory(scratch);
@ -657,7 +663,7 @@ list__parameters(Application_Links *app, General_Memory *general, Partition *scr
}
static void
list_single__parameters(Application_Links *app, General_Memory *general, Partition *scratch,
list_single__parameters(Application_Links *app, Heap *heap, Partition *scratch,
String str, bool32 substrings, bool32 case_insensitive){
Search_Range_Flag flags = 0;
if (substrings){
@ -669,22 +675,22 @@ list_single__parameters(Application_Links *app, General_Memory *general, Partiti
if (case_insensitive){
flags |= SearchFlag_CaseInsensitive;
}
list__parameters(app, general, scratch, &str, 1, flags);
list__parameters(app, heap, scratch, &str, 1, flags);
}
static void
list_query__parameters(Application_Links *app, General_Memory *general, Partition *scratch,
list_query__parameters(Application_Links *app, Heap *heap, Partition *scratch,
bool32 substrings, bool32 case_insensitive){
char space[1024];
String str = get_query_string(app, "List Locations For: ", space, sizeof(space));
if (str.str != 0){
change_active_panel(app);
list_single__parameters(app, general, scratch, str, substrings, case_insensitive);
list_single__parameters(app, heap, scratch, str, substrings, case_insensitive);
}
}
static void
list_identifier__parameters(Application_Links *app, General_Memory *general, Partition *scratch,
list_identifier__parameters(Application_Links *app, Heap *heap, Partition *scratch,
bool32 substrings, bool32 case_insensitive){
View_Summary view = get_active_view(app, AccessProtected);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected);
@ -693,25 +699,25 @@ list_identifier__parameters(Application_Links *app, General_Memory *general, Par
String str = get_token_or_word_under_pos(app, &buffer, view.cursor.pos, space, sizeof(space));
if (str.str != 0){
change_active_panel(app);
list_single__parameters(app, general, scratch, str, substrings, case_insensitive);
list_single__parameters(app, heap, scratch, str, substrings, case_insensitive);
}
}
static void
list_selected_range__parameters(Application_Links *app, General_Memory *general, Partition *scratch,
list_selected_range__parameters(Application_Links *app, Heap *heap, Partition *scratch,
bool32 substrings, bool32 case_insensitive){
View_Summary view = get_active_view(app, AccessProtected);
Temp_Memory temp = begin_temp_memory(scratch);
String str = get_string_in_view_range(app, scratch, &view);
if (str.str != 0){
change_active_panel(app);
list_single__parameters(app, general, scratch, str, substrings, case_insensitive);
list_single__parameters(app, heap, scratch, str, substrings, case_insensitive);
}
end_temp_memory(temp);
}
static void
list_type_definition__parameters(Application_Links *app, General_Memory *general, Partition *scratch,
list_type_definition__parameters(Application_Links *app, Heap *heap, Partition *scratch,
String str){
Temp_Memory temp = begin_temp_memory(scratch);
@ -723,7 +729,7 @@ list_type_definition__parameters(Application_Links *app, General_Memory *general
match_strings[4] = build_string(scratch, "enum " , str, "{");
match_strings[5] = build_string(scratch, "enum " , str, "\n{");
list__parameters(app, general, scratch,
list__parameters(app, heap, scratch,
match_strings, ArrayCount(match_strings), 0);
end_temp_memory(temp);
@ -741,49 +747,49 @@ list_type_definition__parameters(Application_Links *app, General_Memory *general
CUSTOM_COMMAND_SIG(list_all_locations)
CUSTOM_DOC("Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.")
{
list_query__parameters(app, &global_general, &global_part, false, false);
list_query__parameters(app, &global_heap, &global_part, false, false);
}
CUSTOM_COMMAND_SIG(list_all_substring_locations)
CUSTOM_DOC("Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.")
{
list_query__parameters(app, &global_general, &global_part, true, false);
list_query__parameters(app, &global_heap, &global_part, true, false);
}
CUSTOM_COMMAND_SIG(list_all_locations_case_insensitive)
CUSTOM_DOC("Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.")
{
list_query__parameters(app, &global_general, &global_part, false, true);
list_query__parameters(app, &global_heap, &global_part, false, true);
}
CUSTOM_COMMAND_SIG(list_all_substring_locations_case_insensitive)
CUSTOM_DOC("Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.")
{
list_query__parameters(app, &global_general, &global_part, true, true);
list_query__parameters(app, &global_heap, &global_part, true, true);
}
CUSTOM_COMMAND_SIG(list_all_locations_of_identifier)
CUSTOM_DOC("Reads a token or word under the cursor and lists all exact case-sensitive mathces in all open buffers.")
{
list_identifier__parameters(app, &global_general, &global_part, false, false);
list_identifier__parameters(app, &global_heap, &global_part, false, false);
}
CUSTOM_COMMAND_SIG(list_all_locations_of_identifier_case_insensitive)
CUSTOM_DOC("Reads a token or word under the cursor and lists all exact case-insensitive mathces in all open buffers.")
{
list_identifier__parameters(app, &global_general, &global_part, false, true);
list_identifier__parameters(app, &global_heap, &global_part, false, true);
}
CUSTOM_COMMAND_SIG(list_all_locations_of_selection)
CUSTOM_DOC("Reads the string in the selected range and lists all exact case-sensitive mathces in all open buffers.")
{
list_selected_range__parameters(app, &global_general, &global_part, false, false);
list_selected_range__parameters(app, &global_heap, &global_part, false, false);
}
CUSTOM_COMMAND_SIG(list_all_locations_of_selection_case_insensitive)
CUSTOM_DOC("Reads the string in the selected range and lists all exact case-insensitive mathces in all open buffers.")
{
list_selected_range__parameters(app, &global_general, &global_part, false, true);
list_selected_range__parameters(app, &global_heap, &global_part, false, true);
}
CUSTOM_COMMAND_SIG(list_all_locations_of_type_definition)
@ -793,7 +799,7 @@ CUSTOM_DOC("Queries user for string, lists all locations of strings that appear
String str = get_query_string(app, "List Definitions For: ", space, sizeof(space));
if (str.str != 0){
change_active_panel(app);
list_type_definition__parameters(app, &global_general, &global_part, str);
list_type_definition__parameters(app, &global_heap, &global_part, str);
}
}
@ -806,7 +812,7 @@ CUSTOM_DOC("Reads a token or word under the cursor and lists all locations of st
String str = get_token_or_word_under_pos(app, &buffer, view.cursor.pos, space, sizeof(space) - 1);
if (str.str != 0){
change_active_panel(app);
list_type_definition__parameters(app, &global_general, &global_part, str);
list_type_definition__parameters(app, &global_heap, &global_part, str);
}
}
@ -881,7 +887,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with
// NOTE(allen): Initialize the search iterator with the partial word.
complete_state.initialized = true;
Search_Key key = {0};
search_key_alloc(&global_general, &key, &size, 1);
search_key_alloc(&global_heap, &key, &size, 1);
buffer_read_range(app, &buffer, word_start, word_end, key.words[0].str);
key.words[0].size = size;
@ -889,7 +895,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with
// NOTE(allen): Initialize the set of ranges to be searched.
int32_t buffer_count = get_buffer_count(app);
search_set_init(&global_general, &complete_state.set, buffer_count);
search_set_init(&global_heap, &complete_state.set, buffer_count);
Search_Range *ranges = complete_state.set.ranges;
ranges[0].type = SearchRange_Wave;
@ -916,9 +922,9 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with
complete_state.set.count = j;
// NOTE(allen): Initialize the search hit table.
search_hits_init(&global_general, &complete_state.hits, &complete_state.str, 100, (4 << 10));
search_hits_init(&global_heap, &complete_state.hits, &complete_state.str, 100, (4 << 10));
String word = complete_state.iter.key.words[0];
search_hit_add(&global_general, &complete_state.hits, &complete_state.str, word.str, word.size);
search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, word.str, word.size);
complete_state.word_start = word_start;
complete_state.word_end = word_end;
@ -942,7 +948,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with
buffer_read_range(app, &match.buffer, match.start, match.end, spare);
if (search_hit_add(&global_general, &complete_state.hits, &complete_state.str, spare, match_size)){
if (search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, spare, match_size)){
buffer_replace_range(app, &buffer, word_start, word_end, spare, match_size);
view_set_cursor(app, &view, seek_pos(word_start + match_size), true);
@ -957,9 +963,9 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with
complete_state.iter.pos = 0;
complete_state.iter.i = 0;
search_hits_init(&global_general, &complete_state.hits, &complete_state.str, 100, (4 << 10));
search_hits_init(&global_heap, &complete_state.hits, &complete_state.str, 100, (4 << 10));
String word = complete_state.iter.key.words[0];
search_hit_add(&global_general, &complete_state.hits, &complete_state.str, word.str, word.size);
search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, word.str, word.size);
match_size = word.size;
char *str = word.str;

View File

@ -195,17 +195,17 @@ view_get_lister_state(View_Summary *view){
}
static void
init_lister_state(Lister_State *state, General_Memory *general){
init_lister_state(Lister_State *state, Heap *heap){
state->initialized = true;
state->hot_user_data = 0;
state->item_index = 0;
state->set_view_vertical_focus_to_item = false;
state->option_item_count = 0;
if (state->arena.base != 0){
general_memory_free(general, state->arena.base);
heap_free(heap, state->arena.base);
}
int32_t arena_size = (64 << 10);
state->arena = make_part(general_memory_allocate(general, arena_size), arena_size);
state->arena = make_part(heap_allocate(heap, arena_size), arena_size);
memset(&state->lister, 0, sizeof(state->lister));
}
@ -470,7 +470,7 @@ lister_call_refresh_handler(Application_Links *app, Partition *arena, Lister *li
}
static void
lister_call_activate_handler(Application_Links *app, Partition *scratch, General_Memory *general,
lister_call_activate_handler(Application_Links *app, Partition *scratch, Heap *heap,
View_Summary *view, Lister_State *state,
void *user_data, bool32 activated_by_mouse){
Lister *lister = &state->lister;
@ -484,7 +484,7 @@ lister_call_activate_handler(Application_Links *app, Partition *scratch, General
if (view_end_ui_mode(app, view) == 0){
state->initialized = false;
if (state->arena.base != 0){
general_memory_free(general, state->arena.base);
heap_free(heap, state->arena.base);
memset(&state->arena, 0, sizeof(state->arena));
}
}

37
4ed.cpp
View File

@ -192,7 +192,7 @@ do_feedback_message(System_Functions *system, Models *models, String value){
internal View*
panel_make_empty(System_Functions *system, Models *models, Panel *panel){
Assert(panel->view == 0);
View_And_ID new_view = live_set_alloc_view(&models->mem.general, &models->lifetime_allocator, &models->live_set, panel);
View_And_ID new_view = live_set_alloc_view(&models->mem.heap, &models->lifetime_allocator, &models->live_set, panel);
view_set_file(system, models, new_view.view, models->scratch_buffer);
return(new_view.view);
}
@ -254,7 +254,7 @@ COMMAND_DECL(reopen){
if (system->load_file(handle, buffer, size)){
system->load_close(handle);
General_Memory *general = &models->mem.general;
Heap *heap = &models->mem.heap;
File_Edit_Positions edit_poss[16];
int32_t line_number[16];
@ -277,7 +277,7 @@ COMMAND_DECL(reopen){
++vptr_count;
}
file_free(system, &models->app_links, general, file);
file_free(system, &models->app_links, heap, file);
init_normal_file(system, models, buffer, size, file);
for (i32 i = 0; i < vptr_count; ++i){
@ -403,7 +403,7 @@ internal b32
interpret_binding_buffer(Models *models, void *buffer, i32 size){
b32 result = true;
General_Memory *gen = &models->mem.general;
Heap *gen = &models->mem.heap;
Partition *part = &models->mem.part;
Temp_Memory temp = begin_temp_memory(part);
@ -508,7 +508,7 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){
i32 binding_rounded_memsize = l_round_up_i32(binding_memsize, 8);
i32 needed_memsize = map_id_table_rounded_memsize + user_maps_rounded_memsize + binding_rounded_memsize;
new_mapping.memory = general_memory_allocate(gen, needed_memsize);
new_mapping.memory = heap_allocate(gen, needed_memsize);
local_part = make_part(new_mapping.memory, needed_memsize);
// Move ID Table Memory and Pointer
@ -688,7 +688,7 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){
Mapping old_mapping = models->mapping;
if (old_mapping.memory != 0){
// TODO(allen): Do I need to explicity work on recovering the old ids of buffers?
general_memory_free(gen, old_mapping.memory);
heap_free(gen, old_mapping.memory);
}
models->mapping = new_mapping;
@ -974,13 +974,8 @@ app_setup_memory(System_Functions *system, Application_Memory *memory){
Assert(vars != 0);
memset(vars, 0, sizeof(*vars));
vars->models.mem.part = _partition;
#if defined(USE_DEBUG_MEMORY)
general_memory_open(system, &vars->models.mem.general, memory->target_memory, memory->target_memory_size);
#else
general_memory_open(&vars->models.mem.general, memory->target_memory, memory->target_memory_size);
#endif
heap_init(&vars->models.mem.heap);
heap_extend(&vars->models.mem.heap, memory->target_memory, memory->target_memory_size);
return(vars);
}
@ -1067,7 +1062,7 @@ App_Init_Sig(app_init){
umem memsize = KB(8);
void *mem = push_array(partition, u8, (i32)memsize);
parse_context_init_memory(&models->parse_context_memory, mem, memsize);
parse_context_add_default(&models->parse_context_memory, &models->mem.general);
parse_context_add_default(&models->parse_context_memory, &models->mem.heap);
}
{
@ -1080,10 +1075,10 @@ App_Init_Sig(app_init){
}
dynamic_variables_init(&models->variable_layout);
dynamic_variables_block_init(&models->mem.general, &models->dynamic_vars);
dynamic_workspace_init(&models->mem.heap, &models->dynamic_workspace);
// NOTE(allen): file setup
working_set_init(&models->working_set, partition, &vars->models.mem.general);
working_set_init(&models->working_set, partition, &vars->models.mem.heap);
models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH;
models->working_set.default_minimum_base_display_width = DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH;
@ -1095,7 +1090,7 @@ App_Init_Sig(app_init){
// TODO(allen): more robust allocation solution for the clipboard
if (clipboard.str != 0){
String *dest = working_set_next_clipboard_string(&models->mem.general, &models->working_set, clipboard.size);
String *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size);
copy(dest, make_string((char*)clipboard.str, clipboard.size));
}
@ -1131,10 +1126,10 @@ App_Init_Sig(app_init){
{ make_lit_string("*scratch*"), &models->scratch_buffer, false, },
};
General_Memory *general = &models->mem.general;
Heap *heap = &models->mem.heap;
for (i32 i = 0; i < ArrayCount(init_files); ++i){
Editing_File *file = working_set_alloc_always(&models->working_set, general, &models->lifetime_allocator);
buffer_bind_name(models, general, partition, &models->working_set, file, init_files[i].name);
Editing_File *file = working_set_alloc_always(&models->working_set, heap, &models->lifetime_allocator);
buffer_bind_name(models, heap, partition, &models->working_set, file, init_files[i].name);
if (init_files[i].read_only){
init_read_only_file(system, models, file);
@ -1177,7 +1172,7 @@ App_Step_Sig(app_step){
// NOTE(allen): OS clipboard event handling
String clipboard = input->clipboard;
if (clipboard.str){
String *dest =working_set_next_clipboard_string(&models->mem.general, &models->working_set, clipboard.size);
String *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size);
dest->size = eol_convert_in(dest->str, clipboard.str, clipboard.size);
}

View File

@ -19,7 +19,7 @@ access_test(u32 lock_flags, u32 access_flags){
internal void
fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *working_set){
*buffer = null_buffer_summary;
memset(buffer, 0, sizeof(*buffer));
if (!file->is_dummy){
buffer->exists = 1;
buffer->ready = file_is_ready(file);
@ -247,7 +247,7 @@ DOC_SEE(Command_Line_Interface_Flag)
App_Vars *vars = cmd->vars;
Models *models = cmd->models;
Partition *part = &models->mem.part;
General_Memory *general = &models->mem.general;
Heap *heap = &models->mem.heap;
Working_Set *working_set = &models->working_set;
bool32 result = true;
@ -287,11 +287,11 @@ DOC_SEE(Command_Line_Interface_Flag)
// NOTE(allen): If the buffer is specified by name but does not already exist, then create it.
if (file == 0 && buffer_id.name != 0){
file = working_set_alloc_always(working_set, general, &models->lifetime_allocator);
file = working_set_alloc_always(working_set, heap, &models->lifetime_allocator);
Assert(file != 0);
String name = push_string(part, buffer_id.name, buffer_id.name_len);
buffer_bind_name(models, general, part, working_set, file, name);
buffer_bind_name(models, heap, part, working_set, file, name);
init_read_only_file(system, models, file);
}
@ -393,10 +393,10 @@ DOC_SEE(The_4coder_Clipboard)
Command_Data *cmd = (Command_Data*)app->cmd_context;
System_Functions *system = cmd->system;
Models *models = cmd->models;
General_Memory *general = &models->mem.general;
Heap *heap = &models->mem.heap;
Working_Set *working = &models->working_set;
String *dest = working_set_next_clipboard_string(general, working, len);
String *dest = working_set_next_clipboard_string(heap, working, len);
copy_ss(dest, make_string(str, len));
system->post_clipboard(*dest);
}
@ -455,7 +455,7 @@ DOC_RETURN(On success returns an id for the new parse context. If id == 0, then
Command_Data *cmd = (Command_Data*)app->cmd_context;
Models *models = cmd->models;
Parse_Context_ID id = parse_context_add(&models->parse_context_memory, &models->mem.general, kw, kw_count, pp, pp_count);
Parse_Context_ID id = parse_context_add(&models->parse_context_memory, &models->mem.heap, kw, kw_count, pp, pp_count);
return(id);
}
@ -481,17 +481,17 @@ internal_get_buffer_first(Working_Set *working_set, Buffer_Summary *buffer){
internal void
internal_get_buffer_next(Working_Set *working_set, Buffer_Summary *buffer){
Editing_File *file = working_set_get_active_file(working_set, buffer->buffer_id);
if (file){
if (file != 0){
file = (Editing_File*)file->node.next;
if (file != (Editing_File*)&working_set->used_sentinel){
fill_buffer_summary(buffer, file, working_set);
}
else{
*buffer = null_buffer_summary;
memset(buffer, 0, sizeof(*buffer));
}
}
else{
*buffer = null_buffer_summary;
memset(buffer, 0, sizeof(*buffer));
}
}
@ -559,15 +559,13 @@ DOC_SEE(Buffer_ID)
Command_Data *cmd = (Command_Data*)app->cmd_context;
Working_Set *working_set = &cmd->models->working_set;
Buffer_Summary buffer = {0};
Editing_File *file = working_set_get_active_file(working_set, buffer_id);
if (file != 0 && !file->is_dummy){
fill_buffer_summary(&buffer, file, working_set);
if (!access_test(buffer.lock_flags, access)){
buffer = null_buffer_summary;
memset(&buffer, 0, sizeof(buffer));
}
}
return(buffer);
}
@ -588,15 +586,13 @@ DOC_SEE(Access_Flag)
Command_Data *cmd = (Command_Data*)app->cmd_context;
Buffer_Summary buffer = {0};
Working_Set *working_set = &cmd->models->working_set;
Editing_File *file = working_set_contains_name(working_set, make_string(name, len));
if (file != 0 && !file->is_dummy){
fill_buffer_summary(&buffer, file, working_set);
if (!access_test(buffer.lock_flags, access)){
buffer = null_buffer_summary;
memset(&buffer, 0, sizeof(buffer));
}
}
return(buffer);
}
@ -620,17 +616,15 @@ DOC_SEE(Access_Flag)
System_Functions *system = cmd->system;
Models *models = cmd->models;
Working_Set *working_set = &models->working_set;
String fname = make_string(name, len);
Editing_File_Name canon = {0};
if (get_canon_name(system, fname, &canon)){
Editing_File *file = working_set_contains_canon(working_set, canon.name);
fill_buffer_summary(&buffer, file, working_set);
if (!access_test(buffer.lock_flags, access)){
buffer = null_buffer_summary;
memset(&buffer, 0, sizeof(buffer));
}
}
return(buffer);
}
@ -772,7 +766,7 @@ DOC_SEE(Buffer_Batch_Edit_Type)
char *inv_str = (char*)part->base + part->pos;
int32_t inv_str_max = part->max - part->pos;
Edit_Spec spec = edit_compute_batch_spec(&mem->general,
Edit_Spec spec = edit_compute_batch_spec(&mem->heap,
file,
edits, str, str_len,
inverse_edits, inv_str, inv_str_max, edit_count, type);
@ -803,7 +797,7 @@ DOC_SEE(Marker)
Editing_File *file = imp_get_file(cmd, buffer_id);
Managed_Object result = 0;
if (file != 0){
result = (Managed_Object)allocate_markers_state(&models->mem.general, file, marker_count);
result = (Managed_Object)allocate_markers_state(&models->mem.heap, file, marker_count);
}
return(result);
}
@ -816,7 +810,7 @@ DOC_PARAM(access, The access parameter determines what levels of protection this
DOC_SEE(Marker)
*/{
Buffer_Summary buffer = {0};
if (object != 0){
if (marker_object != 0){
void *ptr = IntAsPtr(marker_object);
Buffer_ID buffer_id = get_buffer_id_from_marker_handle(ptr);
buffer = Get_Buffer(app, buffer_id, access);
@ -877,10 +871,10 @@ DOC_SEE(Marker)
}
API_EXPORT bool32
Buffer_Remove_Markers(Application_Links *app, Managed_Object marker)
Buffer_Remove_Markers(Application_Links *app, Managed_Object marker_object)
/*
DOC_PARAM(buffer, The buffer on which the specified markers are attached.)
DOC_PARAM(marker, The marker handle refering to the markers to be detached from the buffer.)
DOC_PARAM(marker_object, The marker handle refering to the markers to be detached from the buffer.)
DOC_RETURN(On success returns non-zero, on failure returns zero.)
DOC(Deactivates the entire range of markers specified by the marker handle and frees the memory used to store the markers internally.)
DOC_SEE(buffer_add_markers)
@ -893,7 +887,7 @@ DOC_SEE(buffer_add_markers)
Buffer_ID buffer_id = get_buffer_id_from_marker_handle(ptr);
Editing_File *file = imp_get_file(cmd, buffer_id);
if (file != 0){
if (markers_free(&models->mem.general, file, ptr)){
if (markers_free(&models->mem.heap, file, ptr)){
result = true;
}
}
@ -1005,7 +999,7 @@ DOC_SEE(Buffer_Setting_ID)
{
if (file->settings.tokens_exist){
if (!value){
file_kill_tokens(system, &models->mem.general, file);
file_kill_tokens(system, &models->mem.heap, file);
}
}
else{
@ -1024,7 +1018,7 @@ DOC_SEE(Buffer_Setting_ID)
{
if (file->settings.tokens_exist){
if ((b8)value != file->settings.tokens_without_strings){
file_kill_tokens(system, &models->mem.general, file);
file_kill_tokens(system, &models->mem.heap, file);
file->settings.tokens_without_strings = (b8)value;
if (!file->settings.virtual_white){
file_first_lex_parallel(system, models, file);
@ -1045,7 +1039,7 @@ DOC_SEE(Buffer_Setting_ID)
if (file->settings.tokens_exist){
if (fixed_value != file->settings.parse_context_id){
file_kill_tokens(system, &models->mem.general, file);
file_kill_tokens(system, &models->mem.heap, file);
file->settings.parse_context_id = fixed_value;
if (!file->settings.virtual_white){
file_first_lex_parallel(system, models, file);
@ -1166,7 +1160,7 @@ DOC_SEE(Buffer_Setting_ID)
if (full_remeasure){
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
file_allocate_character_starts_as_needed(&models->mem.general, file);
file_allocate_character_starts_as_needed(&models->mem.heap, file);
buffer_measure_character_starts(system, font, &file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
file_measure_wraps(system, &models->mem, file, font);
adjust_views_looking_at_file_to_new_cursor(system, models, file);
@ -1302,7 +1296,7 @@ DOC_SEE(Buffer_Create_Flag)
System_Functions *system = cmd->system;
Models *models = cmd->models;
Working_Set *working_set = &models->working_set;
General_Memory *general = &models->mem.general;
Heap *heap = &models->mem.heap;
Partition *part = &models->mem.part;
Buffer_Summary result = {0};
@ -1352,12 +1346,12 @@ DOC_SEE(Buffer_Create_Flag)
if (do_empty_buffer){
if ((flags & BufferCreate_NeverNew) == 0){
file = working_set_alloc_always(working_set, general, &models->lifetime_allocator);
file = working_set_alloc_always(working_set, heap, &models->lifetime_allocator);
if (file != 0){
if (has_canon_name){
buffer_bind_file(system, general, working_set, file, canon.name);
buffer_bind_file(system, heap, working_set, file, canon.name);
}
buffer_bind_name(models, general, part, working_set, file, front_of_directory(fname));
buffer_bind_name(models, heap, part, working_set, file, front_of_directory(fname));
init_normal_file(system, models, 0, 0, file);
fill_buffer_summary(&result, file, cmd);
}
@ -1367,21 +1361,21 @@ DOC_SEE(Buffer_Create_Flag)
Assert(!handle_equal(handle, null_plat_handle));
i32 size = system->load_size(handle);
b32 in_general_mem = false;
b32 in_heap_mem = false;
char *buffer = push_array(part, char, size);
if (buffer == 0){
buffer = (char*)general_memory_allocate(general, size);
buffer = heap_array(heap, char, size);
Assert(buffer != 0);
in_general_mem = true;
in_heap_mem = true;
}
if (system->load_file(handle, buffer, size)){
system->load_close(handle);
file = working_set_alloc_always(working_set, general, &models->lifetime_allocator);
file = working_set_alloc_always(working_set, heap, &models->lifetime_allocator);
if (file != 0){
buffer_bind_file(system, general, working_set, file, canon.name);
buffer_bind_name(models, general, part, working_set, file, front_of_directory(fname));
buffer_bind_file(system, heap, working_set, file, canon.name);
buffer_bind_name(models, heap, part, working_set, file, front_of_directory(fname));
init_normal_file(system, models, buffer, size, file);
fill_buffer_summary(&result, file, cmd);
}
@ -1390,8 +1384,8 @@ DOC_SEE(Buffer_Create_Flag)
system->load_close(handle);
}
if (in_general_mem){
general_memory_free(general, buffer);
if (in_heap_mem){
heap_free(heap, buffer);
}
}
}
@ -1489,8 +1483,8 @@ DOC_SEE(Buffer_Identifier)
if (file->canon.name.size != 0){
buffer_unbind_file(system, working_set, file);
}
file_free(system, &models->app_links, &models->mem.general, file);
working_set_free_file(&models->mem.general, &models->lifetime_allocator, working_set, file);
file_free(system, &models->app_links, &models->mem.heap, file);
working_set_free_file(&models->mem.heap, &models->lifetime_allocator, working_set, file);
File_Node *used = &working_set->used_sentinel;
File_Node *node = used->next;
@ -1735,7 +1729,7 @@ in the system, the call will fail.)
if (vptr != 0 && models->layout.panel_count > 1){
Panel *panel = vptr->transient.panel;
live_set_free_view(&models->mem.general, &models->lifetime_allocator, &models->live_set, vptr);
live_set_free_view(&models->mem.heap, &models->lifetime_allocator, &models->live_set, vptr);
panel->view = 0;
Divider_And_ID div = layout_get_divider(&models->layout, panel->parent);
@ -2230,11 +2224,11 @@ View_Set_UI(Application_Links *app, View_Summary *view, UI_Control *control)
{
Command_Data *cmd = (Command_Data*)app->cmd_context;
Models *models = cmd->models;
General_Memory *general = &models->mem.general;
Heap *heap = &models->mem.heap;
View *vptr = imp_get_view(cmd, view);
if (vptr != 0){
if (vptr->transient.ui_control.items != 0){
general_memory_free(general, vptr->transient.ui_control.items);
heap_free(heap, vptr->transient.ui_control.items);
}
memset(&vptr->transient.ui_control, 0, sizeof(vptr->transient.ui_control));
if (control->count > 0){
@ -2264,7 +2258,7 @@ View_Set_UI(Application_Links *app, View_Summary *view, UI_Control *control)
i32 all_items_size = sizeof(UI_Item)*control->count;
i32 memory_size = all_items_size + string_size;
UI_Item *new_items = (UI_Item*)general_memory_allocate(general, memory_size);
UI_Item *new_items = (UI_Item*)heap_allocate(heap, memory_size);
if (new_items != 0){
char *string_space = (char*)(new_items + control->count);
Partition string_alloc = make_part(string_space, string_size);
@ -2414,8 +2408,8 @@ Get_Intersected_Dynamic_Scope(Application_Links *app, Dynamic_Scope *intersected
i32 member_count = (i32)(push_array(scratch, Lifetime_Object*, 0) - object_ptr_array);
member_count = lifetime_sort_and_dedup_object_set(object_ptr_array, member_count);
General_Memory *general = &models->mem.general;
Lifetime_Key *key = lifetime_get_or_create_intersection_key(general, lifetime_allocator, object_ptr_array, member_count);
Heap *heap = &models->mem.heap;
Lifetime_Key *key = lifetime_get_or_create_intersection_key(heap, lifetime_allocator, object_ptr_array, member_count);
result.type = DynamicScopeType_Intersected;
result.intersected_opaque_handle = (u64)(PtrAsInt(key));
}
@ -2431,9 +2425,9 @@ Managed_Variable_Create(Application_Links *app, char *null_terminated_name, uint
Command_Data *cmd = (Command_Data*)app->cmd_context;
Models *models = cmd->models;
String name = make_string_slowly(null_terminated_name);
General_Memory *general = &models->mem.general;
Heap *heap = &models->mem.heap;
Dynamic_Variable_Layout *layout = &models->variable_layout;
return(dynamic_variables_create(general, layout, name, default_value));
return(dynamic_variables_create(heap, layout, name, default_value));
}
API_EXPORT Managed_Variable_ID
@ -2452,53 +2446,55 @@ Managed_Variable_Create_Or_Get_ID(Application_Links *app, char *null_terminated_
Command_Data *cmd = (Command_Data*)app->cmd_context;
Models *models = cmd->models;
String name = make_string_slowly(null_terminated_name);
General_Memory *general = &models->mem.general;
Heap *heap = &models->mem.heap;
Dynamic_Variable_Layout *layout = &models->variable_layout;
return(dynamic_variables_lookup_or_create(general, layout, name, default_value));
return(dynamic_variables_lookup_or_create(heap, layout, name, default_value));
}
internal Dynamic_Workspace*
get_dynamic_workspace(Command_Data *cmd, Dynamic_Scope handle){
Models *models = cmd->models;
Dynamic_Workspace *workspace = 0;
switch (handle.type){
case DynamicScopeType_Global:
{
workspace = &models->dynamic_workspace;
}break;
case DynamicScopeType_Intersected:
{
Lifetime_Key *key = (Lifetime_Key*)IntAsPtr(handle.intersected_opaque_handle);
Lifetime_Allocator *lifetime_allocator = &models->lifetime_allocator;
if (lifetime_key_check(lifetime_allocator, key)){
workspace = &key->dynamic_workspace;
}
}break;
case DynamicScopeType_Buffer:
{
Editing_File *file = imp_get_file(cmd, handle.buffer_id);
if (file != 0){
workspace = &file->dynamic_workspace;
}
}break;
case DynamicScopeType_View:
{
View *vptr = imp_get_view(cmd, handle.view_id);
if (vptr != 0){
workspace = &vptr->transient.dynamic_workspace;
}
}break;
}
return(workspace);
}
internal bool32
get_dynamic_variable(Command_Data *cmd, Dynamic_Scope handle, int32_t location, uint64_t **ptr_out){
Models *models = cmd->models;
Lifetime_Allocator *lifetime_allocator = &models->lifetime_allocator;
General_Memory *general = &models->mem.general;
Heap *heap = &models->mem.heap;
Dynamic_Variable_Layout *layout = &models->variable_layout;
Dynamic_Variable_Block *block = 0;
switch (handle.type){
case DynamicScopeType_Global:
{
block = &models->dynamic_vars;
}break;
case DynamicScopeType_Intersected:
{
Lifetime_Key *key = (Lifetime_Key*)IntAsPtr(handle.intersected_opaque_handle);
if (lifetime_key_check(lifetime_allocator, key)){
block = &key->dynamic_vars;
}
}break;
case DynamicScopeType_Buffer:
{
Editing_File *file = imp_get_file(cmd, handle.buffer_id);
if (file != 0){
block = &file->dynamic_vars;
}
}break;
case DynamicScopeType_View:
{
View *vptr = imp_get_view(cmd, handle.view_id);
if (vptr != 0){
block = &vptr->transient.dynamic_vars;
}
}break;
}
Dynamic_Workspace *workspace = get_dynamic_workspace(cmd, handle);
bool32 result = false;
if (layout != 0 && block != 0){
if (dynamic_variables_get_ptr(general, layout, block, location, ptr_out)){
if (workspace != 0){
if (dynamic_variables_get_ptr(heap, layout, &workspace->var_block, location, ptr_out)){
result = true;
}
}
@ -2529,6 +2525,40 @@ Managed_Variable_Get(Application_Links *app, Dynamic_Scope scope, Managed_Variab
return(false);
}
API_EXPORT Managed_Object
Managed_Memory_Alloc(Application_Links *app, Dynamic_Scope scope, int32_t size)
{
Command_Data *cmd = (Command_Data*)app->cmd_context;
Models *models = cmd->models;
Heap *heap = &models->mem.heap;
Dynamic_Workspace *workspace = get_dynamic_workspace(cmd, scope);
Managed_Object result = 0;
if (workspace != 0){
result = (Managed_Object)dynamic_allocate(heap, &workspace->mem_bank, size);
}
return(result);
}
API_EXPORT bool32
Managed_Memory_Set(Application_Links *app, Managed_Object object, uint32_t start, uint32_t size, void *mem)
{
// Command_Data *cmd = (Command_Data*)app->cmd_context;
// Models *models = cmd->models;
u8 *ptr = (u8*)IntAsPtr(object);
memcpy(ptr + start, mem, size);
return(true);
}
API_EXPORT bool32
Managed_Memory_Get(Application_Links *app, Managed_Object object, uint32_t start, uint32_t size, void *mem_out)
{
// Command_Data *cmd = (Command_Data*)app->cmd_context;
// Models *models = cmd->models;
u8 *ptr = (u8*)IntAsPtr(object);
memcpy(mem_out, ptr + start, size);
return(true);
}
API_EXPORT User_Input
Get_User_Input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type)
/*

View File

@ -68,7 +68,7 @@ struct Models{
Parse_Context_Memory parse_context_memory;
Dynamic_Variable_Layout variable_layout;
Dynamic_Variable_Block dynamic_vars;
Dynamic_Workspace dynamic_workspace;
Lifetime_Allocator lifetime_allocator;
Editing_File *message_buffer;

View File

@ -21,17 +21,22 @@
#include "4ed_system.h"
#define PREFERRED_ALIGNMENT 8
#define USE_DEBUG_MEMORY
#define FSTRING_IMPLEMENTATION
#define FSTRING_C
#include "4coder_lib/4coder_string.h"
#include "4coder_lib/4coder_mem.h"
#include "4coder_lib/4coder_arena.h"
#include "4coder_lib/4coder_heap.h"
#include "4coder_lib/4coder_table.h"
#include "4coder_lib/4coder_utf8.h"
#if defined(USE_DEBUG_MEMORY)
# include "4ed_debug_mem.h"
#endif
struct Mem_Options{
Partition part;
Heap heap;
};
#include "4coder_lib/4coder_arena.cpp"
#include "4coder_lib/4coder_heap.cpp"
#include "4ed_render_target.h"
#include "4ed_render_format.h"

View File

@ -435,14 +435,14 @@ get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start){
internal void
file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *file, Font_Pointers font){
General_Memory *general = &mem->general;
Heap *heap = &mem->heap;
Partition *part = &mem->part;
Temp_Memory temp = begin_temp_memory(part);
file_allocate_wraps_as_needed(general, file);
file_allocate_indents_as_needed(general, file, file->state.buffer.line_count);
file_allocate_wrap_positions_as_needed(general, file, file->state.buffer.line_count);
file_allocate_wraps_as_needed(heap, file);
file_allocate_indents_as_needed(heap, file, file->state.buffer.line_count);
file_allocate_wrap_positions_as_needed(heap, file, file->state.buffer.line_count);
Buffer_Measure_Wrap_Params params;
params.buffer = &file->state.buffer;
@ -506,7 +506,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
else{
do_wrap = 1;
wrap_unit_end = wrap_indent_marks[stage+1].wrap_position;
file_allocate_wrap_positions_as_needed(general, file, wrap_position_index);
file_allocate_wrap_positions_as_needed(heap, file, wrap_position_index);
file->state.wrap_positions[wrap_position_index++] = stop.pos;
}
}
@ -569,7 +569,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
wrap_unit_end = wrap_end_result;
if (x > width){
do_wrap = 1;
file_allocate_wrap_positions_as_needed(general, file, wrap_position_index);
file_allocate_wrap_positions_as_needed(heap, file, wrap_position_index);
file->state.wrap_positions[wrap_position_index++] = stop.pos;
}
else{
@ -801,17 +801,17 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
next_stickieness = stickieness_guess(next_type, this_type, next_flags, this_flags, 0);
}
i32 general_stickieness = this_stickieness;
if (general_stickieness < next_stickieness){
general_stickieness = next_stickieness;
i32 heap_stickieness = this_stickieness;
if (heap_stickieness < next_stickieness){
heap_stickieness = next_stickieness;
}
if (wrap_state.wrap_x.paren_top != 0 && this_type == CPP_TOKEN_COMMA){
general_stickieness = 0;
heap_stickieness = 0;
}
wrappable_score = 64*50;
wrappable_score += 101 - general_stickieness - wrap_state.wrap_x.paren_safe_top*80;
wrappable_score += 101 - heap_stickieness - wrap_state.wrap_x.paren_safe_top*80;
potential_marks[potential_count].wrap_position = next_wrap_position;
potential_marks[potential_count].line_shift = current_shift.shift;
@ -914,7 +914,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
current_line_shift = clamp_top(current_line_shift, current_width - edge_tolerance);
if (stop.wrap_line_index >= file->state.line_indent_max){
file_allocate_indents_as_needed(general, file, stop.wrap_line_index);
file_allocate_indents_as_needed(heap, file, stop.wrap_line_index);
}
file->state.line_indents[stop.wrap_line_index] = current_line_shift;
@ -925,7 +925,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
++file->state.wrap_line_count;
file_allocate_wrap_positions_as_needed(general, file, wrap_position_index);
file_allocate_wrap_positions_as_needed(heap, file, wrap_position_index);
file->state.wrap_positions[wrap_position_index++] = size;
file->state.wrap_position_count = wrap_position_index;

View File

@ -1,91 +0,0 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 01.14.2017
*
*
*
*/
// TOP
#ifndef FED_DEBUG_MEM_H
#define FED_DEBUG_MEM_H
// NOTE(allen): Prevent any future instantiation of 4coder_mem.h
#define FCODER_MEM_H
#if !defined(OS_PAGE_SIZE)
#define OS_PAGE_SIZE 4096
#endif
struct Debug_GM{
System_Functions *system;
};
static void
debug_gm_open(System_Functions *system, Debug_GM *general, void *memory, i32 size){
general->system = system;
}
static void*
debug_gm_allocate(Debug_GM *general, int32_t size){
System_Functions *system = general->system;
local_persist u32 page_round_val = OS_PAGE_SIZE-1;
int32_t page_rounded_size = (size + page_round_val) & (~page_round_val);
u8 *result = (u8*)system->memory_allocate(page_rounded_size + OS_PAGE_SIZE);
system->memory_set_protection(result + page_rounded_size, OS_PAGE_SIZE, 0);
local_persist u32 align_round_val = PREFERRED_ALIGNMENT-1;
int32_t align_rounded_size = (size + align_round_val) & (~align_round_val);
int32_t offset = page_rounded_size - align_rounded_size;
return(result + offset);
}
static void
debug_gm_free(Debug_GM *general, void *memory){
u8 *ptr = (u8*)memory;
umem val = *(umem*)(&ptr);
val &= ~(0xFFF);
ptr = *(u8**)(&val);
Assert(sizeof(val) == sizeof(ptr));
System_Functions *system = general->system;
system->memory_free(ptr, 0);
}
static void*
debug_gm_reallocate(Debug_GM *general, void *old, int32_t old_size, int32_t size){
void *result = debug_gm_allocate(general, size);
memcpy(result, old, Min(old_size, size));
debug_gm_free(general, old);
return(result);
}
inline void*
debug_gm_reallocate_nocopy(Debug_GM *general, void *old, int32_t size){
debug_gm_free(general, old);
void *result = debug_gm_allocate(general, size);
return(result);
}
// Redefine the normal general memory names to go to these debug names.
#define General_Memory Debug_GM
struct Debug_Mem_Options{
Partition part;
General_Memory general;
};
#define Mem_Options Debug_Mem_Options
#define general_memory_open(sys,gen,mem,siz) debug_gm_open(sys,gen,mem,siz)
#define general_memory_allocate(gen,siz) debug_gm_allocate(gen,siz)
#define general_memory_free(gen,siz) debug_gm_free(gen,siz)
#define general_memory_reallocate(gen,old,old_size,new_size) debug_gm_reallocate(gen,old,old_size,new_size)
#define general_memory_reallocate_nocopy(gen,old,new_size) debug_gm_reallocate_nocopy(gen,old,new_size)
#endif
// BOTTOM

View File

@ -28,9 +28,9 @@ dynamic_variables_lookup(Dynamic_Variable_Layout *layout, String name){
}
internal Managed_Variable_ID
dynamic_variables_create__always(General_Memory *general, Dynamic_Variable_Layout *layout, String name, u64 default_value){
dynamic_variables_create__always(Heap *heap, Dynamic_Variable_Layout *layout, String name, u64 default_value){
int32_t alloc_size = name.size + 1 + sizeof(Dynamic_Variable_Slot);
void *ptr = general_memory_allocate(general, alloc_size);
void *ptr = heap_allocate(heap, alloc_size);
if (ptr != 0){
Dynamic_Variable_Slot *new_slot = (Dynamic_Variable_Slot*)ptr;
char *c_str = (char*)(new_slot + 1);
@ -47,41 +47,41 @@ dynamic_variables_create__always(General_Memory *general, Dynamic_Variable_Layou
}
internal Managed_Variable_ID
dynamic_variables_lookup_or_create(General_Memory *general, Dynamic_Variable_Layout *layout, String name, u64 default_value){
dynamic_variables_lookup_or_create(Heap *heap, Dynamic_Variable_Layout *layout, String name, u64 default_value){
Managed_Variable_ID lookup_id = dynamic_variables_lookup(layout, name);
if (lookup_id != ManagedVariableIndex_ERROR){
return(lookup_id);
}
return(dynamic_variables_create__always(general, layout, name, default_value));
return(dynamic_variables_create__always(heap, layout, name, default_value));
}
internal i32
dynamic_variables_create(General_Memory *general, Dynamic_Variable_Layout *layout, String name, u64 default_value){
dynamic_variables_create(Heap *heap, Dynamic_Variable_Layout *layout, String name, u64 default_value){
Managed_Variable_ID lookup_id = dynamic_variables_lookup(layout, name);
if (lookup_id == ManagedVariableIndex_ERROR){
return(dynamic_variables_create__always(general, layout, name, default_value));
return(dynamic_variables_create__always(heap, layout, name, default_value));
}
return(ManagedVariableIndex_ERROR);
}
internal void
dynamic_variables_block_init(General_Memory *general, Dynamic_Variable_Block *block){
dynamic_variables_block_init(Heap *heap, Dynamic_Variable_Block *block){
i32 max = 64;
block->val_array = (u64*)general_memory_allocate(general, sizeof(u64)*max);
block->val_array = heap_array(heap, u64, max);
block->count = 0;
block->max = max;
}
internal void
dynamic_variables_block_free(General_Memory *general, Dynamic_Variable_Block *block){
general_memory_free(general, block->val_array);
dynamic_variables_block_free(Heap *heap, Dynamic_Variable_Block *block){
heap_free(heap, block->val_array);
}
internal void
dynamic_variables_block_grow_max_to(General_Memory *general, i32 new_max, Dynamic_Variable_Block *block){
u64 *new_array = (u64*)general_memory_allocate(general, sizeof(u64)*new_max);
dynamic_variables_block_grow_max_to(Heap *heap, i32 new_max, Dynamic_Variable_Block *block){
u64 *new_array = heap_array(heap, u64, new_max);
memcpy(new_array, block->val_array, sizeof(u64)*block->count);
general_memory_free(general, block->val_array);
heap_free(heap, block->val_array);
block->val_array = new_array;
}
@ -101,7 +101,7 @@ dynamic_variables_block_fill_unset_values(Dynamic_Variable_Layout *layout, Dynam
}
internal b32
dynamic_variables_get_ptr(General_Memory *general,
dynamic_variables_get_ptr(Heap *heap,
Dynamic_Variable_Layout *layout, Dynamic_Variable_Block *block,
i32 location, u64 **ptr_out){
b32 result = false;
@ -110,7 +110,7 @@ dynamic_variables_get_ptr(General_Memory *general,
if (index >= block->count){
i32 minimum_max = layout->location_counter - 1;
if (block->max < minimum_max){
dynamic_variables_block_grow_max_to(general, minimum_max*2, block);
dynamic_variables_block_grow_max_to(heap, minimum_max*2, block);
}
dynamic_variables_block_fill_unset_values(layout, block, index + 1);
}
@ -122,25 +122,55 @@ dynamic_variables_get_ptr(General_Memory *general,
////////////////////////////////
internal void*
dynamic_allocate(Heap *heap, Dynamic_Memory_Bank *bank, i32 size){
void *ptr = heap_allocate(&bank->heap, size);
if (ptr == 0){
i32 alloc_size = clamp_bottom(4096, size*4);
void *new_block = heap_allocate(heap, alloc_size);
if (new_block != 0){
Dynamic_Memory_Header *header = (Dynamic_Memory_Header*)new_block;
sll_push(bank->first, bank->last, header);
heap_extend(&bank->heap, header + 1, alloc_size - sizeof(*header));
ptr = heap_allocate(&bank->heap, size);
}
}
return(ptr);
}
////////////////////////////////
internal void
dynamic_workspace_init(Heap *heap, Dynamic_Workspace *workspace){
dynamic_variables_block_init(heap, &workspace->var_block);
}
internal void
dynamic_workspace_free(Heap *heap, Dynamic_Workspace *workspace){
dynamic_variables_block_free(heap, &workspace->var_block);
}
////////////////////////////////
internal u64
ptr_check__hash(Lifetime_Key *key){
ptr_check__hash(void *key){
u64 x = (u64)(PtrAsInt(key));
return(x >> 3);
return((x >> 3) | bit_63);
}
internal b32
ptr_check_table_check(Ptr_Check_Table *table, void *key){
u32 max = table->max;
if (max > 0 && table->count > 0){
u64 hash = ptr_check_hash(key);
u64 hash = ptr_check__hash(key);
u32 first_index = hash%max;
u32 index = first_index;
void *keys = table->keys;
void **keys = table->keys;
for (;;){
if (keys[index] == key){
return(true);
}
else if (hashes[index] == LifetimeKeyHash_Empty){
else if (keys[index] == IntAsPtr(LifetimeKeyHash_Empty)){
return(false);
}
index += 1;
@ -156,17 +186,17 @@ ptr_check_table_check(Ptr_Check_Table *table, void *key){
}
internal Ptr_Check_Table
ptr_check_table_copy(General_Memory *general, Ptr_Check_Table *table, u32 new_max);
ptr_check_table_copy(Heap *heap, Ptr_Check_Table table, u32 new_max);
internal void
ptr_check_table_insert(General_Memory *general, Ptr_Check_Table *table, void *key){
ptr_check_table_insert(Heap *heap, Ptr_Check_Table *table, void *key){
{
u32 max = table->max;
u32 count = table->count;
if (max == 0 || (count + 1)*6 > max*5){
Assert(general != 0);
Ptr_Check_Table new_table = ptr_check_table_copy(general, *table, max*2);
general_memory_free(general, table->mem_ptr);
Assert(heap != 0);
Ptr_Check_Table new_table = ptr_check_table_copy(heap, *table, max*2);
heap_free(heap, table->keys);
*table = new_table;
}
}
@ -174,7 +204,7 @@ ptr_check_table_insert(General_Memory *general, Ptr_Check_Table *table, void *ke
{
u32 max = table->max;
if (max > 0 && table->count > 0){
u64 hash = ptr_check_hash(key);
u64 hash = ptr_check__hash(key);
u32 first_index = hash%max;
u32 index = first_index;
void **keys = table->keys;
@ -199,7 +229,7 @@ internal void
ptr_check_table_erase(Ptr_Check_Table *table, Lifetime_Key *erase_key){
u32 max = table->max;
if (max > 0 && table->count > 0){
u64 hash = ptr_check_hash(erase_key);
u64 hash = ptr_check__hash(erase_key);
u32 first_index = hash%max;
u32 index = first_index;
void **keys = table->keys;
@ -208,7 +238,7 @@ ptr_check_table_erase(Ptr_Check_Table *table, Lifetime_Key *erase_key){
keys[index] = 0;
return;
}
else if (hashes[index] == LifetimeKeyHash_Empty){
else if (keys[index] == IntAsPtr(LifetimeKeyHash_Empty)){
return;
}
index += 1;
@ -222,17 +252,16 @@ ptr_check_table_erase(Ptr_Check_Table *table, Lifetime_Key *erase_key){
}
}
internal Lifetime_Key_Check_Table
ptr_check_table_copy(General_Memory *general, Lifetime_Key_Check_Table *table, u32 new_max){
Lifetime_Key_Check_Table new_table = {0};
internal Ptr_Check_Table
ptr_check_table_copy(Heap *heap, Ptr_Check_Table table, u32 new_max){
Ptr_Check_Table new_table = {0};
new_table.max = clamp_bottom(table.max, new_max);
new_table.max = clamp_bottom(307, new_table.max);
i32 item_size = sizeof(*new_table.keys);
new_table.keys = (Lifetime_Key**)general_memory_allocate(general, item_size*new_table.max);
memset(new_table.keys, 0, item_size*new_table.max);
new_table.keys = heap_array(heap, void*, new_table.max);
memset(new_table.keys, 0, sizeof(*new_table.keys)*new_table.max);
for (u32 i = 0; i < table.max; i += 1){
u64 k = (u64)(PtrAsInt(table.keys[i]));
if (k > 1){
if ((k&bit_63) == 0){
ptr_check_table_insert(0, &new_table, table.keys[i]);
}
}
@ -284,17 +313,17 @@ lifetime__key_table_lookup(Lifetime_Key_Table *table, u64 hash, Lifetime_Object
}
internal Lifetime_Key_Table
lifetime__key_table_copy(General_Memory *general, Lifetime_Key_Table table, u32 new_max);
lifetime__key_table_copy(Heap *heap, Lifetime_Key_Table table, u32 new_max);
internal void
lifetime__key_table_insert(General_Memory *general, Lifetime_Key_Table *table, u64 hash, Lifetime_Key *key){
lifetime__key_table_insert(Heap *heap, Lifetime_Key_Table *table, u64 hash, Lifetime_Key *key){
{
u32 max = table->max;
u32 count = table->count;
if (max == 0 || (count + 1)*6 > max*5){
Assert(general != 0);
Lifetime_Key_Table new_table = lifetime__key_table_copy(general, *table, max*2);
general_memory_free(general, table->mem_ptr);
Assert(heap != 0);
Lifetime_Key_Table new_table = lifetime__key_table_copy(heap, *table, max*2);
heap_free(heap, table->mem_ptr);
*table = new_table;
}
}
@ -356,12 +385,12 @@ lifetime__key_table_erase(Lifetime_Key_Table *table, Lifetime_Key *erase_key){
}
internal Lifetime_Key_Table
lifetime__key_table_copy(General_Memory *general, Lifetime_Key_Table table, u32 new_max){
lifetime__key_table_copy(Heap *heap, Lifetime_Key_Table table, u32 new_max){
Lifetime_Key_Table new_table = {0};
new_table.max = clamp_bottom(table.max, new_max);
new_table.max = clamp_bottom(307, new_table.max);
i32 item_size = sizeof(*new_table.hashes) + sizeof(*new_table.keys);
new_table.mem_ptr = general_memory_allocate(general, item_size*new_table.max);
new_table.mem_ptr = heap_allocate(heap, item_size*new_table.max);
memset(new_table.mem_ptr, 0, item_size*new_table.max);
new_table.hashes = (u64*)(new_table.mem_ptr);
new_table.keys = (Lifetime_Key**)(new_table.hashes + new_table.max);
@ -374,10 +403,10 @@ lifetime__key_table_copy(General_Memory *general, Lifetime_Key_Table table, u32
}
internal void
lifetime__free_key(General_Memory *general, Lifetime_Allocator *lifetime_allocator,
lifetime__free_key(Heap *heap, Lifetime_Allocator *lifetime_allocator,
Lifetime_Key *key, Lifetime_Object *skip_object){
// Deinit
dynamic_variables_block_free(general, &key->dynamic_vars);
dynamic_workspace_free(heap, &key->dynamic_workspace);
// Remove From Objects
i32 count = key->count;
@ -420,16 +449,16 @@ lifetime__free_key(General_Memory *general, Lifetime_Allocator *lifetime_allocat
// Free
lifetime__key_table_erase(&lifetime_allocator->key_table, key);
ptr_check_table_erase(&lifetime_allocator->key_check_table, key);
general_memory_free(general, key->members);
heap_free(heap, key->members);
zdll_push_back(lifetime_allocator->free_keys.first, lifetime_allocator->free_keys.last, key);
}
internal Lifetime_Key_Ref_Node*
lifetime__alloc_key_reference_node(General_Memory *general, Lifetime_Allocator *lifetime_allocator){
lifetime__alloc_key_reference_node(Heap *heap, Lifetime_Allocator *lifetime_allocator){
Lifetime_Key_Ref_Node *result = lifetime_allocator->free_key_references.first;
if (result == 0){
i32 new_node_count = 32;
Lifetime_Key_Ref_Node *new_nodes = (Lifetime_Key_Ref_Node*)general_memory_allocate(general, sizeof(Lifetime_Key_Ref_Node)*new_node_count);
Lifetime_Key_Ref_Node *new_nodes = heap_array(heap, Lifetime_Key_Ref_Node, new_node_count);
Lifetime_Key_Ref_Node *new_node_ptr = new_nodes;
for (i32 i = 0; i < new_node_count; i += 1, new_node_ptr += 1){
zdll_push_back(lifetime_allocator->free_key_references.first,
@ -445,7 +474,7 @@ lifetime__alloc_key_reference_node(General_Memory *general, Lifetime_Allocator *
}
internal void
lifetime__object_add_key(General_Memory *general, Lifetime_Allocator *lifetime_allocator,
lifetime__object_add_key(Heap *heap, Lifetime_Allocator *lifetime_allocator,
Lifetime_Object *object, Lifetime_Key *key){
Lifetime_Key_Ref_Node *last_node = object->key_node_last;
b32 insert_on_new_node = false;
@ -462,7 +491,7 @@ lifetime__object_add_key(General_Memory *general, Lifetime_Allocator *lifetime_a
}
}
if (insert_on_new_node){
Lifetime_Key_Ref_Node *new_node = lifetime__alloc_key_reference_node(general, lifetime_allocator);
Lifetime_Key_Ref_Node *new_node = lifetime__alloc_key_reference_node(heap, lifetime_allocator);
zdll_push_back(object->key_node_first, object->key_node_last, new_node);
memset(new_node->keys, 0, sizeof(new_node->keys));
new_node->keys[0] = key;
@ -471,11 +500,11 @@ lifetime__object_add_key(General_Memory *general, Lifetime_Allocator *lifetime_a
}
internal Lifetime_Object*
lifetime_alloc_object(General_Memory *general, Lifetime_Allocator *lifetime_allocator, i32 user_type, void *user_back_ptr){
lifetime_alloc_object(Heap *heap, Lifetime_Allocator *lifetime_allocator, i32 user_type, void *user_back_ptr){
Lifetime_Object *object = lifetime_allocator->free_objects.first;
if (object == 0){
i32 new_object_count = 256;
Lifetime_Object *new_objects = (Lifetime_Object*)general_memory_allocate(general, sizeof(Lifetime_Object)*new_object_count);
Lifetime_Object *new_objects = heap_array(heap, Lifetime_Object, new_object_count);
Lifetime_Object *new_object_ptr = new_objects;
for (i32 i = 0; i < new_object_count; i += 1, new_object_ptr += 1){
zdll_push_back(lifetime_allocator->free_objects.first, lifetime_allocator->free_objects.last, new_object_ptr);
@ -495,7 +524,7 @@ lifetime_alloc_object(General_Memory *general, Lifetime_Allocator *lifetime_allo
}
internal void
lifetime_free_object(General_Memory *general, Lifetime_Allocator *lifetime_allocator,
lifetime_free_object(Heap *heap, Lifetime_Allocator *lifetime_allocator,
Lifetime_Object *lifetime_object){
i32 key_i = 0;
for (Lifetime_Key_Ref_Node *node = lifetime_object->key_node_first;
@ -503,7 +532,7 @@ lifetime_free_object(General_Memory *general, Lifetime_Allocator *lifetime_alloc
node = node->next){
i32 one_past_last = clamp_top(ArrayCount(node->keys), lifetime_object->key_count - key_i);
for (i32 i = 0; i < one_past_last; i += 1){
lifetime__free_key(general, lifetime_allocator, node->keys[i], lifetime_object);
lifetime__free_key(heap, lifetime_allocator, node->keys[i], lifetime_object);
}
key_i += one_past_last;
}
@ -558,7 +587,7 @@ lifetime_sort_and_dedup_object_set(Lifetime_Object **ptr_array, i32 count){
}
internal Lifetime_Key*
lifetime_get_or_create_intersection_key(General_Memory *general, Lifetime_Allocator *lifetime_allocator, Lifetime_Object **object_ptr_array, i32 count){
lifetime_get_or_create_intersection_key(Heap *heap, Lifetime_Allocator *lifetime_allocator, Lifetime_Object **object_ptr_array, i32 count){
u64 hash = lifetime__key_hash(object_ptr_array, count);
// Lookup
@ -572,7 +601,7 @@ lifetime_get_or_create_intersection_key(General_Memory *general, Lifetime_Alloca
Lifetime_Key *new_key = lifetime_allocator->free_keys.first;
if (new_key == 0){
i32 new_key_count = 256;
Lifetime_Key *new_keys = (Lifetime_Key*)general_memory_allocate(general, sizeof(Lifetime_Key)*new_key_count);
Lifetime_Key *new_keys = heap_array(heap, Lifetime_Key, new_key_count);
Lifetime_Key *new_key_ptr = new_keys;
for (i32 i = 0; i < new_key_count; i += 1, new_key_ptr += 1){
zdll_push_back(lifetime_allocator->free_keys.first, lifetime_allocator->free_keys.last, new_key_ptr);
@ -586,17 +615,17 @@ lifetime_get_or_create_intersection_key(General_Memory *general, Lifetime_Alloca
Lifetime_Object **object_ptr = object_ptr_array;
for (i32 i = 0; i < count; i += 1, object_ptr += 1){
Lifetime_Object *object = *object_ptr;
lifetime__object_add_key(general, lifetime_allocator, object, new_key);
lifetime__object_add_key(heap, lifetime_allocator, object, new_key);
}
// Initialize
new_key->members = (Lifetime_Object**)general_memory_allocate(general, sizeof(Lifetime_Object*)*count);
memcpy(new_key->members, object_ptr_array, sizeof(Lifetime_Object*)*count);
new_key->members = heap_array(heap, Lifetime_Object*, count);
memcpy(new_key->members, object_ptr_array, sizeof(*new_key->members)*count);
new_key->count = count;
dynamic_variables_block_init(general, &new_key->dynamic_vars);
dynamic_workspace_init(heap, &new_key->dynamic_workspace);
lifetime__key_table_insert(general, &lifetime_allocator->key_table, hash, new_key);
ptr_check_table_insert(general, &lifetime_allocator->key_check_table, new_key);
lifetime__key_table_insert(heap, &lifetime_allocator->key_table, hash, new_key);
ptr_check_table_insert(heap, &lifetime_allocator->key_check_table, new_key);
return(new_key);
}

View File

@ -33,6 +33,25 @@ struct Dynamic_Variable_Block{
////////////////////////////////
struct Dynamic_Memory_Header{
Dynamic_Memory_Header *next;
};
struct Dynamic_Memory_Bank{
Heap heap;
Dynamic_Memory_Header *first;
Dynamic_Memory_Header *last;
};
////////////////////////////////
struct Dynamic_Workspace{
Dynamic_Variable_Block var_block;
Dynamic_Memory_Bank mem_bank;
};
////////////////////////////////
struct Ptr_Check_Table{
void **keys;
u32 count;
@ -74,7 +93,7 @@ struct Lifetime_Key{
struct{
struct Lifetime_Object **members;
i32 count;
Dynamic_Variable_Block dynamic_vars;
Dynamic_Workspace dynamic_workspace;
};
};
};
@ -113,7 +132,7 @@ struct Lifetime_Allocator{
Lifetime_Object_List free_objects;
Lifetime_Key_List free_keys;
Lifetime_Key_Table key_table;
Lifetime_Ptr_Check_Table key_check_table;
Ptr_Check_Table key_check_table;
};
struct Lifetime_Key_With_Opaque_ID{

View File

@ -10,11 +10,11 @@
// TOP
inline void
edit_pre_maintenance(System_Functions *system, General_Memory *general, Editing_File *file){
edit_pre_maintenance(System_Functions *system, Heap *heap, Editing_File *file){
if (file->state.still_lexing){
system->cancel_job(BACKGROUND_THREADS, file->state.lex_job);
if (file->state.swap_array.tokens){
general_memory_free(general, file->state.swap_array.tokens);
heap_free(heap, file->state.swap_array.tokens);
file->state.swap_array.tokens = 0;
}
file->state.still_lexing = 0;
@ -142,11 +142,11 @@ edit_single__inner(System_Functions *system, Models *models, Editing_File *file,
// NOTE(allen): fixing stuff beforewards????
file_update_history_before_edit(mem, file, spec.step, spec.str, history_mode);
edit_pre_maintenance(system, &mem->general, file);
edit_pre_maintenance(system, &mem->heap, file);
// NOTE(allen): actual text replacement
i32 shift_amount = 0;
General_Memory *general = &mem->general;
Heap *heap = &mem->heap;
Partition *part = &mem->part;
char *str = (char*)spec.str;
@ -162,11 +162,11 @@ edit_single__inner(System_Functions *system, Models *models, Editing_File *file,
while (buffer_replace_range(&file->state.buffer, start, end, str, str_len, &shift_amount, part->base + part->pos, scratch_size, &request_amount)){
void *new_data = 0;
if (request_amount > 0){
new_data = general_memory_allocate(general, request_amount);
new_data = heap_allocate(heap, request_amount);
}
void *old_data = buffer_edit_provide_memory(&file->state.buffer, new_data, request_amount);
if (old_data){
general_memory_free(general, old_data);
heap_free(heap, old_data);
}
}
@ -191,10 +191,10 @@ edit_single__inner(System_Functions *system, Models *models, Editing_File *file,
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
Assert(font.valid);
file_grow_starts_as_needed(general, buffer, line_shift);
file_grow_starts_as_needed(heap, buffer, line_shift);
buffer_remeasure_starts(buffer, line_start, line_end, line_shift, shift_amount);
file_allocate_character_starts_as_needed(general, file);
file_allocate_character_starts_as_needed(heap, file);
buffer_remeasure_character_starts(system, font, buffer, line_start, line_end, line_shift, file->state.character_starts, 0, file->settings.virtual_white);
file_measure_wraps(system, &models->mem, file, font);
@ -220,7 +220,7 @@ edit_single(System_Functions *system, Models *models, Editing_File *file,
}
internal Edit_Spec
edit_compute_batch_spec(General_Memory *general,
edit_compute_batch_spec(Heap *heap,
Editing_File *file,
Buffer_Edit *edits, char *str_base, i32 str_size,
Buffer_Edit *inverse_array, char *inv_str, i32 inv_max, i32 edit_count, i32 batch_type){
@ -232,8 +232,8 @@ edit_compute_batch_spec(General_Memory *general,
InvalidCodePath;
}
i32 first_child = undo_children_push(general, &file->state.undo.children, edits, edit_count, (u8*)(str_base), str_size);
i32 inverse_first_child = undo_children_push(general, &file->state.undo.children, inverse_array, edit_count, (u8*)(inv_str), inv_str_pos);
i32 first_child = undo_children_push(heap, &file->state.undo.children, edits, edit_count, (u8*)(str_base), str_size);
i32 inverse_first_child = undo_children_push(heap, &file->state.undo.children, inverse_array, edit_count, (u8*)(inv_str), inv_str_pos);
Edit_Spec spec = {};
spec.step.type = ED_NORMAL;
@ -250,14 +250,14 @@ edit_batch(System_Functions *system, Models *models, Editing_File *file,
Edit_Spec spec, History_Mode history_mode, Buffer_Batch_Edit_Type batch_type){
Mem_Options *mem = &models->mem;
General_Memory *general = &mem->general;
Heap *heap = &mem->heap;
Partition *part = &mem->part;
Editing_Layout *layout = &models->layout;
// NOTE(allen): fixing stuff "beforewards"???
Assert(spec.str == 0);
file_update_history_before_edit(mem, file, spec.step, 0, history_mode);
edit_pre_maintenance(system, &mem->general, file);
edit_pre_maintenance(system, &mem->heap, file);
// NOTE(allen): actual text replacement
u8 *str_base = file->state.undo.children.strings;
@ -275,11 +275,11 @@ edit_batch(System_Functions *system, Models *models, Editing_File *file,
scratch_size, &request_amount)){
void *new_data = 0;
if (request_amount > 0){
new_data = general_memory_allocate(general, request_amount);
new_data = heap_allocate(heap, request_amount);
}
void *old_data = buffer_edit_provide_memory(&file->state.buffer, new_data, request_amount);
if (old_data){
general_memory_free(general, old_data);
heap_free(heap, old_data);
}
}
@ -341,13 +341,13 @@ edit_batch(System_Functions *system, Models *models, Editing_File *file,
// it from cursor fixing is because you're a lazy asshole.
// NOTE(allen): meta data
file_measure_starts(general, &file->state.buffer);
file_measure_starts(heap, &file->state.buffer);
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
Assert(font.valid);
// TODO(allen): write the remeasurement version
file_allocate_character_starts_as_needed(general, file);
file_allocate_character_starts_as_needed(heap, file);
buffer_measure_character_starts(system, font, &file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
file_measure_wraps(system, &models->mem, file, font);

View File

@ -27,16 +27,13 @@ init_file_markers_state(Editing_File_Markers *markers){
}
internal void
clear_file_markers_state(Application_Links *app, General_Memory *general, Editing_File_Markers *markers){
clear_file_markers_state(Application_Links *app, Heap *heap, Editing_File_Markers *markers){
Marker_Array *sentinel = &markers->sentinel;
for (Marker_Array *marker_array = sentinel->next;
marker_array != sentinel;
marker_array = sentinel->next){
if (marker_array->callback != 0){
marker_array->callback(app, marker_array, marker_array + 1, marker_array->user_data_size);
}
dll_remove(marker_array);
general_memory_free(general, marker_array);
heap_free(heap, marker_array);
}
Assert(sentinel->next == sentinel);
Assert(sentinel->prev == sentinel);
@ -45,9 +42,9 @@ clear_file_markers_state(Application_Links *app, General_Memory *general, Editin
}
internal void*
allocate_markers_state(General_Memory *general, Editing_File *file, u32 new_array_max){
allocate_markers_state(Heap *heap, Editing_File *file, u32 new_array_max){
u32 memory_size = sizeof(Marker_Array) + sizeof(Marker)*new_array_max;
Marker_Array *array = (Marker_Array*)general_memory_allocate(general, memory_size);
Marker_Array *array = (Marker_Array*)heap_allocate(heap, memory_size);
dll_insert_back(&file->markers.sentinel, array);
array->buffer_id = file->id;
@ -67,15 +64,6 @@ get_buffer_id_from_marker_handle(void *handle){
return(result.id);
}
internal Data
get_user_data_from_marker_handle(void *handle){
Marker_Array *markers = (Marker_Array*)handle;
Data data;
data.data = (u8*)markers + 1;
data.size = markers->user_data_size;
return(data);
}
internal b32
markers_set(Editing_File *file, void *handle, u32 first_index, u32 count, Marker *source){
Assert(file != 0);
@ -126,7 +114,7 @@ markers_get(Editing_File *file, void *handle, u32 first_index, u32 count, Marker
}
internal b32
markers_free(General_Memory *general, Editing_File *file, void *handle){
markers_free(Heap *heap, Editing_File *file, void *handle){
Assert(file != 0);
if (handle == 0){
return(false);
@ -140,7 +128,7 @@ markers_free(General_Memory *general, Editing_File *file, void *handle){
dll_remove(markers);
file->markers.marker_count -= markers->count;
--file->markers.array_count;
general_memory_free(general, markers);
heap_free(heap, markers);
return(true);
}
@ -333,15 +321,14 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file,
if (filename != 0){
Mem_Options *mem = &models->mem;
if (models->hook_save_file){
if (models->hook_save_file != 0){
models->hook_save_file(&models->app_links, file->id.id);
}
i32 max = 0, size = 0;
b32 dos_write_mode = file->settings.dos_write_mode;
char *data = 0;
Gap_Buffer *buffer = &file->state.buffer;
b32 dos_write_mode = file->settings.dos_write_mode;
i32 max = 0;
if (dos_write_mode){
max = buffer_size(buffer) + buffer->line_count + 1;
}
@ -349,21 +336,23 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file,
max = buffer_size(buffer);
}
b32 used_general = 0;
b32 used_heap = 0;
Temp_Memory temp = begin_temp_memory(&mem->part);
char empty = 0;
char *data = 0;
if (max == 0){
data = &empty;
}
else{
data = (char*)push_array(&mem->part, char, max);
if (!data){
used_general = 1;
data = (char*)general_memory_allocate(&mem->general, max);
used_heap = 1;
data = heap_array(&mem->heap, char, max);
}
}
Assert(data != 0);
i32 size = 0;
if (dos_write_mode){
size = buffer_convert_out(buffer, data, max);
}
@ -391,8 +380,8 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file,
file_set_dirty_flag(file, DirtyState_UpToDate);
if (used_general){
general_memory_free(&mem->general, data);
if (used_heap){
heap_free(&mem->heap, data);
}
end_temp_memory(temp);
@ -507,35 +496,33 @@ file_compute_cursor(System_Functions *system, Editing_File *file, Buffer_Seek se
////////////////////////////////
internal i32
file_grow_starts_as_needed(General_Memory *general, Gap_Buffer *buffer, i32 additional_lines){
file_grow_starts_as_needed(Heap *heap, Gap_Buffer *buffer, i32 additional_lines){
b32 result = GROW_NOT_NEEDED;
i32 max = buffer->line_max;
i32 count = buffer->line_count;
i32 target_lines = count + additional_lines;
if (target_lines > max || max == 0){
max = l_round_up_i32(target_lines + max, KB(1));
i32 *new_lines = (i32*)general_memory_reallocate(general, buffer->line_starts, sizeof(i32)*count, sizeof(f32)*max);
if (new_lines){
i32 *new_lines = heap_array(heap, i32, max);
if (new_lines != 0){
result = GROW_SUCCESS;
buffer->line_max = max;
memcpy(new_lines, buffer->line_starts, sizeof(*new_lines)*count);
heap_free(heap, buffer->line_starts);
buffer->line_starts = new_lines;
buffer->line_max = max;
}
else{
result = GROW_FAILED;
}
}
return(result);
}
internal void
file_measure_starts(General_Memory *general, Gap_Buffer *buffer){
file_measure_starts(Heap *heap, Gap_Buffer *buffer){
if (buffer->line_starts == 0){
i32 max = buffer->line_max = KB(1);
buffer->line_starts = (i32*)general_memory_allocate(general, max*sizeof(i32));
buffer->line_starts = heap_array(heap, i32, max);
Assert(buffer->line_starts != 0);
}
@ -543,25 +530,29 @@ file_measure_starts(General_Memory *general, Gap_Buffer *buffer){
for (;buffer_measure_starts(&state, buffer);){
i32 count = state.count;
i32 max = ((buffer->line_max + 1) << 1);
i32 *new_lines = (i32*)general_memory_reallocate(general, buffer->line_starts, sizeof(i32)*count, sizeof(i32)*max);
Assert(new_lines);
i32 *new_lines = heap_array(heap, i32, max);
Assert(new_lines != 0);
memcpy(new_lines, buffer->line_starts, sizeof(*new_lines)*count);
heap_free(heap, buffer->line_starts);
buffer->line_starts = new_lines;
buffer->line_max = max;
}
}
internal void
file_allocate_metadata_as_needed(General_Memory *general, Gap_Buffer *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){
file_allocate_metadata_as_needed(Heap *heap, Gap_Buffer *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){
if (*mem == 0){
i32 max = l_round_up_i32(((count + 1)*2), KB(1));
*mem = general_memory_allocate(general, max*item_size);
*mem = heap_allocate(heap, max*item_size);
*mem_max_count = max;
Assert(*mem != 0);
}
else if (*mem_max_count < count){
i32 old_max = *mem_max_count;
i32 max = l_round_up_i32(((count + 1)*2), KB(1));
void *new_mem = general_memory_reallocate(general, *mem, item_size*old_max, item_size*max);
void *new_mem = heap_allocate(heap, item_size*max);
memcpy(new_mem, *mem, item_size*old_max);
heap_free(heap, *mem);
*mem = new_mem;
*mem_max_count = max;
Assert(*mem != 0);
@ -569,31 +560,31 @@ file_allocate_metadata_as_needed(General_Memory *general, Gap_Buffer *buffer, vo
}
inline void
file_allocate_character_starts_as_needed(General_Memory *general, Editing_File *file){
file_allocate_metadata_as_needed(general,
file_allocate_character_starts_as_needed(Heap *heap, Editing_File *file){
file_allocate_metadata_as_needed(heap,
&file->state.buffer, (void**)&file->state.character_starts,
&file->state.character_start_max, file->state.buffer.line_count + 1, sizeof(i32));
}
internal void
file_allocate_indents_as_needed(General_Memory *general, Editing_File *file, i32 min_last_index){
file_allocate_indents_as_needed(Heap *heap, Editing_File *file, i32 min_last_index){
i32 min_amount = min_last_index + 1;
file_allocate_metadata_as_needed(general,
file_allocate_metadata_as_needed(heap,
&file->state.buffer, (void**)&file->state.line_indents,
&file->state.line_indent_max, min_amount, sizeof(f32));
}
inline void
file_allocate_wraps_as_needed(General_Memory *general, Editing_File *file){
file_allocate_metadata_as_needed(general,
file_allocate_wraps_as_needed(Heap *heap, Editing_File *file){
file_allocate_metadata_as_needed(heap,
&file->state.buffer, (void**)&file->state.wrap_line_index,
&file->state.wrap_max, file->state.buffer.line_count + 1, sizeof(f32));
}
inline void
file_allocate_wrap_positions_as_needed(General_Memory *general, Editing_File *file, i32 min_last_index){
file_allocate_wrap_positions_as_needed(Heap *heap, Editing_File *file, i32 min_last_index){
i32 min_amount = min_last_index + 1;
file_allocate_metadata_as_needed(general,
file_allocate_metadata_as_needed(heap,
&file->state.buffer, (void**)&file->state.wrap_positions,
&file->state.wrap_position_max, min_amount, sizeof(f32));
}
@ -602,7 +593,7 @@ file_allocate_wrap_positions_as_needed(General_Memory *general, Editing_File *fi
internal void
file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, u32 flags){
General_Memory *general = &models->mem.general;
Heap *heap = &models->mem.heap;
Partition *part = &models->mem.part;
Open_File_Hook_Function *hook_open_file = models->hook_open_file;
Application_Links *app_links = &models->app_links;
@ -615,7 +606,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
if (page_size < KB(4)){
page_size = KB(4);
}
void *data = general_memory_allocate(general, page_size);
void *data = heap_allocate(heap, page_size);
buffer_init_provide_page(&init, data, page_size);
}
@ -635,9 +626,9 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
Assert(font.valid);
{
file_measure_starts(general, &file->state.buffer);
file_measure_starts(heap, &file->state.buffer);
file_allocate_character_starts_as_needed(general, file);
file_allocate_character_starts_as_needed(heap, file);
buffer_measure_character_starts(system, font, &file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
file_measure_wraps(system, &models->mem, file, font);
@ -649,24 +640,24 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
// TODO(allen): Redo undo system (if you don't mind the pun)
i32 request_size = KB(64);
file->state.undo.undo.max = request_size;
file->state.undo.undo.strings = (u8*)general_memory_allocate(general, request_size);
file->state.undo.undo.edit_max = request_size / sizeof(Edit_Step);
file->state.undo.undo.edits = (Edit_Step*)general_memory_allocate(general, request_size);
file->state.undo.undo.strings = (u8*)heap_allocate(heap, request_size);
file->state.undo.undo.edit_max = request_size/sizeof(Edit_Step);
file->state.undo.undo.edits = (Edit_Step*)heap_allocate(heap, request_size);
file->state.undo.redo.max = request_size;
file->state.undo.redo.strings = (u8*)general_memory_allocate(general, request_size);
file->state.undo.redo.edit_max = request_size / sizeof(Edit_Step);
file->state.undo.redo.edits = (Edit_Step*)general_memory_allocate(general, request_size);
file->state.undo.redo.strings = (u8*)heap_allocate(heap, request_size);
file->state.undo.redo.edit_max = request_size/sizeof(Edit_Step);
file->state.undo.redo.edits = (Edit_Step*)heap_allocate(heap, request_size);
file->state.undo.history.max = request_size;
file->state.undo.history.strings = (u8*)general_memory_allocate(general, request_size);
file->state.undo.history.edit_max = request_size / sizeof(Edit_Step);
file->state.undo.history.edits = (Edit_Step*)general_memory_allocate(general, request_size);
file->state.undo.history.strings = (u8*)heap_allocate(heap, request_size);
file->state.undo.history.edit_max = request_size/sizeof(Edit_Step);
file->state.undo.history.edits = (Edit_Step*)heap_allocate(heap, request_size);
file->state.undo.children.max = request_size;
file->state.undo.children.strings = (u8*)general_memory_allocate(general, request_size);
file->state.undo.children.edit_max = request_size / sizeof(Buffer_Edit);
file->state.undo.children.edits = (Buffer_Edit*)general_memory_allocate(general, request_size);
file->state.undo.children.strings = (u8*)heap_allocate(heap, request_size);
file->state.undo.children.edit_max = request_size/sizeof(Buffer_Edit);
file->state.undo.children.edits = (Buffer_Edit*)heap_allocate(heap, request_size);
file->state.undo.history_block_count = 1;
file->state.undo.history_head_block = 0;
@ -680,42 +671,42 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
}
internal void
file_free(System_Functions *system, Application_Links *app, General_Memory *general, Editing_File *file){
file_free(System_Functions *system, Application_Links *app, Heap *heap, Editing_File *file){
if (file->state.still_lexing){
system->cancel_job(BACKGROUND_THREADS, file->state.lex_job);
if (file->state.swap_array.tokens){
general_memory_free(general, file->state.swap_array.tokens);
heap_free(heap, file->state.swap_array.tokens);
file->state.swap_array.tokens = 0;
}
}
if (file->state.token_array.tokens){
general_memory_free(general, file->state.token_array.tokens);
heap_free(heap, file->state.token_array.tokens);
}
clear_file_markers_state(app, general, &file->markers);
clear_file_markers_state(app, heap, &file->markers);
Gap_Buffer *buffer = &file->state.buffer;
if (buffer->data){
general_memory_free(general, buffer->data);
general_memory_free(general, buffer->line_starts);
heap_free(heap, buffer->data);
heap_free(heap, buffer->line_starts);
}
general_memory_free(general, file->state.wrap_line_index);
general_memory_free(general, file->state.character_starts);
general_memory_free(general, file->state.line_indents);
heap_free(heap, file->state.wrap_line_index);
heap_free(heap, file->state.character_starts);
heap_free(heap, file->state.line_indents);
if (file->state.undo.undo.edits){
general_memory_free(general, file->state.undo.undo.strings);
general_memory_free(general, file->state.undo.undo.edits);
heap_free(heap, file->state.undo.undo.strings);
heap_free(heap, file->state.undo.undo.edits);
general_memory_free(general, file->state.undo.redo.strings);
general_memory_free(general, file->state.undo.redo.edits);
heap_free(heap, file->state.undo.redo.strings);
heap_free(heap, file->state.undo.redo.edits);
general_memory_free(general, file->state.undo.history.strings);
general_memory_free(general, file->state.undo.history.edits);
heap_free(heap, file->state.undo.history.strings);
heap_free(heap, file->state.undo.history.edits);
general_memory_free(general, file->state.undo.children.strings);
general_memory_free(general, file->state.undo.children.edits);
heap_free(heap, file->state.undo.children.strings);
heap_free(heap, file->state.undo.children.edits);
}
}

View File

@ -48,7 +48,7 @@ struct Marker_Array{
u32 max;
};
#define MarkerArrayBase(a) (Marker*)((u8*)(a) + sizeof(Marker_Array) + ((Marker_Array*)(a))->rounded_user_data_size)
#define MarkerArrayBase(a) (Marker*)((u8*)(a) + sizeof(Marker_Array))
struct Editing_File_Markers{
Marker_Array sentinel;
@ -128,7 +128,7 @@ struct Editing_File{
b32 is_loading;
b32 is_dummy;
Editing_File_State state;
Dynamic_Variable_Block dynamic_vars;
Dynamic_Workspace dynamic_workspace;
Lifetime_Object *lifetime_object;
Editing_File_Markers markers;
Editing_File_Name base_name;

View File

@ -12,7 +12,7 @@
internal
Job_Callback_Sig(job_full_lex){
Editing_File *file = (Editing_File*)data[0];
General_Memory *general = (General_Memory*)data[1];
Heap *heap = (Heap*)data[1];
Models *models = (Models*)data[2];
Parse_Context parse_context = parse_context_get(&models->parse_context_memory, file->settings.parse_context_id, memory->data, memory->size);
@ -108,7 +108,7 @@ Job_Callback_Sig(job_full_lex){
system->acquire_lock(FRAME_LOCK);
{
Assert(file->state.swap_array.tokens == 0);
file->state.swap_array.tokens = (Cpp_Token*)general_memory_allocate(general, new_max*sizeof(Cpp_Token));
file->state.swap_array.tokens = heap_array(heap, Cpp_Token, new_max);
}
system->release_lock(FRAME_LOCK);
@ -123,7 +123,7 @@ Job_Callback_Sig(job_full_lex){
file_token_array->count = tokens.count;
file_token_array->max_count = new_max;
if (file_token_array->tokens){
general_memory_free(general, file_token_array->tokens);
heap_free(heap, file_token_array->tokens);
}
file_token_array->tokens = file->state.swap_array.tokens;
file->state.swap_array.tokens = 0;
@ -138,17 +138,17 @@ Job_Callback_Sig(job_full_lex){
}
internal void
file_kill_tokens(System_Functions *system, General_Memory *general, Editing_File *file){
file_kill_tokens(System_Functions *system, Heap *heap, Editing_File *file){
file->settings.tokens_exist = 0;
if (file->state.still_lexing){
system->cancel_job(BACKGROUND_THREADS, file->state.lex_job);
if (file->state.swap_array.tokens){
general_memory_free(general, file->state.swap_array.tokens);
heap_free(heap, file->state.swap_array.tokens);
file->state.swap_array.tokens = 0;
}
}
if (file->state.token_array.tokens){
general_memory_free(general, file->state.token_array.tokens);
heap_free(heap, file->state.token_array.tokens);
}
file->state.tokens_complete = 0;
file->state.token_array = null_cpp_token_array;
@ -156,7 +156,7 @@ file_kill_tokens(System_Functions *system, General_Memory *general, Editing_File
internal void
file_first_lex_parallel(System_Functions *system, Models *models, Editing_File *file){
General_Memory *general = &models->mem.general;
Heap *heap = &models->mem.heap;
file->settings.tokens_exist = true;
if (file->is_loading == 0 && file->state.still_lexing == 0){
@ -168,7 +168,7 @@ file_first_lex_parallel(System_Functions *system, Models *models, Editing_File *
Job_Data job;
job.callback = job_full_lex;
job.data[0] = file;
job.data[1] = general;
job.data[1] = heap;
job.data[2] = models;
file->state.lex_job = system->post_job(BACKGROUND_THREADS, job);
}
@ -178,7 +178,7 @@ internal void
file_first_lex_serial(Models *models, Editing_File *file){
Mem_Options *mem = &models->mem;
Partition *part = &mem->part;
General_Memory *general = &mem->general;
Heap *heap = &mem->heap;
file->settings.tokens_exist = true;
Assert(!file->state.still_lexing);
@ -238,14 +238,15 @@ file_first_lex_serial(Models *models, Editing_File *file){
case LexResult_NeedTokenMemory:
{
u32 new_max = l_round_up_u32(swap_array->count + new_tokens.count + 1, KB(1));
u32 new_mem_max = new_max*sizeof(Cpp_Token);
u32 old_mem_count = swap_array->count*sizeof(Cpp_Token);
if (swap_array->tokens == 0){
swap_array->tokens = (Cpp_Token*)general_memory_allocate(general, new_mem_max);
swap_array->tokens = heap_array(heap, Cpp_Token, new_max);
}
else{
swap_array->tokens = (Cpp_Token*)
general_memory_reallocate(general, swap_array->tokens, old_mem_count, new_mem_max);
u32 old_count = swap_array->count;
Cpp_Token *new_tokens = heap_array(heap, Cpp_Token, new_max);
memcpy(new_tokens, swap_array->tokens, sizeof(*new_tokens)*old_count);
heap_free(heap, swap_array->tokens);
swap_array->tokens = new_tokens;
}
swap_array->max_count = new_max;
@ -267,7 +268,7 @@ file_first_lex_serial(Models *models, Editing_File *file){
token_array->count = swap_array->count;
token_array->max_count = swap_array->max_count;
if (token_array->tokens != 0){
general_memory_free(general, token_array->tokens);
heap_free(heap, token_array->tokens);
}
token_array->tokens = swap_array->tokens;
@ -288,7 +289,7 @@ file_first_lex_serial(Models *models, Editing_File *file){
internal b32
file_relex_parallel(System_Functions *system, Models *models, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){
Mem_Options *mem = &models->mem;
General_Memory *general = &mem->general;
Heap *heap = &mem->heap;
Partition *part = &mem->part;
if (file->state.token_array.tokens == 0){
@ -372,7 +373,9 @@ file_relex_parallel(System_Functions *system, Models *models, Editing_File *file
i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array);
if (new_count > array->max_count){
i32 new_max = l_round_up_i32(new_count, KB(1));
void *memory = general_memory_reallocate(general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token));
void *memory = heap_allocate(heap, new_max*sizeof(Cpp_Token));
memcpy(memory, array->tokens, array->count*sizeof(Cpp_Token));
heap_free(heap, array->tokens);
array->tokens = (Cpp_Token*)memory;
array->max_count = new_max;
}
@ -412,7 +415,7 @@ file_relex_parallel(System_Functions *system, Models *models, Editing_File *file
Job_Data job;
job.callback = job_full_lex;
job.data[0] = file;
job.data[1] = general;
job.data[1] = heap;
job.data[2] = models;
file->state.lex_job = system->post_job(BACKGROUND_THREADS, job);
result = false;
@ -424,7 +427,7 @@ file_relex_parallel(System_Functions *system, Models *models, Editing_File *file
internal b32
file_relex_serial(Models *models, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){
Mem_Options *mem = &models->mem;
General_Memory *general = &mem->general;
Heap *heap = &mem->heap;
Partition *part = &mem->part;
if (file->state.token_array.tokens == 0){
@ -496,7 +499,10 @@ file_relex_serial(Models *models, Editing_File *file, i32 start_i, i32 end_i, i3
i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array);
if (new_count > array->max_count){
i32 new_max = l_round_up_i32(new_count, KB(1));
array->tokens = (Cpp_Token*)general_memory_reallocate(general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token));
Cpp_Token *new_tokens = heap_array(heap, Cpp_Token, new_max);
memcpy(new_tokens, array->tokens, array->count*sizeof(Cpp_Token));
heap_free(heap, array->tokens);
array->tokens = new_tokens;
array->max_count = new_max;
}

View File

@ -28,7 +28,7 @@ parse_context_valid_id(Parse_Context_Memory *parse_mem, Parse_Context_ID id){
}
internal Parse_Context_ID
parse_context_add(Parse_Context_Memory *parse_mem, General_Memory *general, Parser_String_And_Type *kw_sats, u32 kw_count, Parser_String_And_Type *pp_sats, u32 pp_count){
parse_context_add(Parse_Context_Memory *parse_mem, Heap *heap, Parser_String_And_Type *kw_sats, u32 kw_count, Parser_String_And_Type *pp_sats, u32 pp_count){
Stored_Parse_Context_Slot *slot = 0;
if (parse_mem->free_sentinel.next != &parse_mem->free_sentinel){
slot = parse_mem->free_sentinel.next;
@ -45,7 +45,7 @@ parse_context_add(Parse_Context_Memory *parse_mem, General_Memory *general, Pars
umem pp_memsize = cpp_get_table_memory_size_string_lengths(&pp_sats->length, stride, pp_count);
umem memsize = kw_memsize + pp_memsize + sizeof(Stored_Parse_Context);
void *mem = general_memory_allocate(general, (i32)memsize);
void *mem = heap_allocate(heap, (i32)memsize);
Stored_Parse_Context *parse_context = (Stored_Parse_Context*)mem;
u8 *kw_mem = (u8*)(parse_context+1);
@ -70,7 +70,7 @@ parse_context_add(Parse_Context_Memory *parse_mem, General_Memory *general, Pars
}
internal u32
parse_context_add_default(Parse_Context_Memory *parse_mem, General_Memory *general){
parse_context_add_default(Parse_Context_Memory *parse_mem, Heap *heap){
Stored_Parse_Context_Slot *slot = 0;
if (parse_mem->free_sentinel.next != &parse_mem->free_sentinel){
slot = parse_mem->free_sentinel.next;
@ -86,7 +86,7 @@ parse_context_add_default(Parse_Context_Memory *parse_mem, General_Memory *gener
umem pp_memsize = cpp_get_table_memory_size_default(CPP_TABLE_PREPROCESSOR_DIRECTIVES);
umem memsize = kw_memsize + pp_memsize + sizeof(Stored_Parse_Context);
void *mem = general_memory_allocate(general, (i32)(memsize));
void *mem = heap_allocate(heap, (i32)(memsize));
Stored_Parse_Context *parse_context = (Stored_Parse_Context*)mem;
u8 *kw_mem = (u8*)(parse_context+1);

View File

@ -10,54 +10,62 @@
// TOP
internal void
undo_stack_grow_string(General_Memory *general, Edit_Stack *stack, i32 extra_size){
undo_stack_grow_string(Heap *heap, Edit_Stack *stack, i32 extra_size){
i32 old_max = stack->max;
u8 *old_str = stack->strings;
i32 new_max = old_max*2 + extra_size;
u8 *new_str = (u8*)general_memory_reallocate(general, old_str, old_max, new_max);
u8 *new_str = heap_array(heap, u8, new_max);
memcpy(new_str, old_str, sizeof(*new_str)*old_max);
heap_free(heap, old_str);
stack->strings = new_str;
stack->max = new_max;
}
internal void
undo_stack_grow_edits(General_Memory *general, Edit_Stack *stack){
undo_stack_grow_edits(Heap *heap, Edit_Stack *stack){
i32 old_max = stack->edit_max;
Edit_Step *old_eds = stack->edits;
i32 new_max = old_max*2 + 2;
Edit_Step *new_eds = (Edit_Step*)general_memory_reallocate(general, old_eds, old_max*sizeof(Edit_Step), new_max*sizeof(Edit_Step));
Edit_Step *new_eds = heap_array(heap, Edit_Step, new_max);
memcpy(new_eds, old_eds, sizeof(*new_eds)*old_max);
heap_free(heap, old_eds);
stack->edits = new_eds;
stack->edit_max = new_max;
}
internal void
child_stack_grow_string(General_Memory *general, Small_Edit_Stack *stack, i32 extra_size){
child_stack_grow_string(Heap *heap, Small_Edit_Stack *stack, i32 extra_size){
i32 old_max = stack->max;
u8 *old_str = stack->strings;
i32 new_max = old_max*2 + extra_size;
u8 *new_str = (u8*)general_memory_reallocate(general, old_str, old_max, new_max);
u8 *new_str = heap_array(heap, u8, new_max);
memcpy(new_str, old_str, sizeof(*new_str)*old_max);
heap_free(heap, old_str);
stack->strings = new_str;
stack->max = new_max;
}
internal void
child_stack_grow_edits(General_Memory *general, Small_Edit_Stack *stack, i32 amount){
child_stack_grow_edits(Heap *heap, Small_Edit_Stack *stack, i32 amount){
i32 old_max = stack->edit_max;
Buffer_Edit *old_eds = stack->edits;
i32 new_max = old_max*2 + amount;
Buffer_Edit *new_eds = (Buffer_Edit*)general_memory_reallocate(general, old_eds, old_max*sizeof(Buffer_Edit), new_max*sizeof(Buffer_Edit));
Buffer_Edit *new_eds = heap_array(heap, Buffer_Edit, new_max);
memcpy(new_eds, old_eds, sizeof(*new_eds)*new_max);
heap_free(heap, old_eds);
stack->edits = new_eds;
stack->edit_max = new_max;
}
internal i32
undo_children_push(General_Memory *general, Small_Edit_Stack *children, Buffer_Edit *edits, i32 edit_count, u8 *strings, i32 string_size){
undo_children_push(Heap *heap, Small_Edit_Stack *children, Buffer_Edit *edits, i32 edit_count, u8 *strings, i32 string_size){
i32 result = children->edit_count;
if (children->edit_count + edit_count > children->edit_max){
child_stack_grow_edits(general, children, edit_count);
child_stack_grow_edits(heap, children, edit_count);
}
if (children->size + string_size > children->max){
child_stack_grow_string(general, children, string_size);
child_stack_grow_string(heap, children, string_size);
}
memcpy(children->edits + children->edit_count, edits, edit_count*sizeof(Buffer_Edit));
@ -76,7 +84,7 @@ undo_children_push(General_Memory *general, Small_Edit_Stack *children, Buffer_E
}
internal Edit_Step*
file_post_undo(General_Memory *general, Editing_File *file, Edit_Step step, b32 do_merge, b32 can_merge){
file_post_undo(Heap *heap, Editing_File *file, Edit_Step step, b32 do_merge, b32 can_merge){
if (step.type == ED_NORMAL){
file->state.undo.redo.size = 0;
file->state.undo.redo.edit_count = 0;
@ -87,7 +95,7 @@ file_post_undo(General_Memory *general, Editing_File *file, Edit_Step step, b32
if (step.child_count == 0){
if (step.edit.end - step.edit.start + undo->size > undo->max){
undo_stack_grow_string(general, undo, step.edit.end - step.edit.start);
undo_stack_grow_string(heap, undo, step.edit.end - step.edit.start);
}
Buffer_Edit inv;
@ -115,7 +123,7 @@ file_post_undo(General_Memory *general, Editing_File *file, Edit_Step step, b32
}
else{
if (undo->edit_count == undo->edit_max){
undo_stack_grow_edits(general, undo);
undo_stack_grow_edits(heap, undo);
}
result = undo->edits + (undo->edit_count++);
@ -132,7 +140,7 @@ file_post_undo(General_Memory *general, Editing_File *file, Edit_Step step, b32
inv_step.inverse_child_count = step.child_count;
if (undo->edit_count == undo->edit_max){
undo_stack_grow_edits(general, undo);
undo_stack_grow_edits(heap, undo);
}
result = undo->edits + (undo->edit_count++);
*result = inv_step;
@ -151,12 +159,12 @@ undo_stack_pop(Edit_Stack *stack){
}
internal void
file_post_redo(General_Memory *general, Editing_File *file, Edit_Step step){
file_post_redo(Heap *heap, Editing_File *file, Edit_Step step){
Edit_Stack *redo = &file->state.undo.redo;
if (step.child_count == 0){
if (step.edit.end - step.edit.start + redo->size > redo->max){
undo_stack_grow_string(general, redo, step.edit.end - step.edit.start);
undo_stack_grow_string(heap, redo, step.edit.end - step.edit.start);
}
Buffer_Edit inv;
@ -167,7 +175,7 @@ file_post_redo(General_Memory *general, Editing_File *file, Edit_Step step){
inv_step.type = ED_REDO;
if (redo->edit_count == redo->edit_max){
undo_stack_grow_edits(general, redo);
undo_stack_grow_edits(heap, redo);
}
redo->edits[redo->edit_count++] = inv_step;
}
@ -181,7 +189,7 @@ file_post_redo(General_Memory *general, Editing_File *file, Edit_Step step){
inv_step.inverse_child_count = step.child_count;
if (redo->edit_count == redo->edit_max){
undo_stack_grow_edits(general, redo);
undo_stack_grow_edits(heap, redo);
}
redo->edits[redo->edit_count++] = inv_step;
}
@ -210,7 +218,7 @@ file_unpost_history_block(Editing_File *file){
}
internal Edit_Step*
file_post_history(General_Memory *general, Editing_File *file, Edit_Step step, b32 do_merge, b32 can_merge){
file_post_history(Heap *heap, Editing_File *file, Edit_Step step, b32 do_merge, b32 can_merge){
Edit_Stack *history = &file->state.undo.history;
Edit_Step *result = 0;
@ -224,7 +232,7 @@ file_post_history(General_Memory *general, Editing_File *file, Edit_Step step, b
if (step.child_count == 0){
if (step.edit.end - step.edit.start + history->size > history->max){
undo_stack_grow_string(general, history, step.edit.end - step.edit.start);
undo_stack_grow_string(heap, history, step.edit.end - step.edit.start);
}
Buffer_Edit inv;
@ -252,7 +260,7 @@ file_post_history(General_Memory *general, Editing_File *file, Edit_Step step, b
}
else{
if (history->edit_count == history->edit_max){
undo_stack_grow_edits(general, history);
undo_stack_grow_edits(heap, history);
}
result = history->edits + (history->edit_count++);
}
@ -269,7 +277,7 @@ file_post_history(General_Memory *general, Editing_File *file, Edit_Step step, b
inv_step.child_count = step.inverse_child_count;
if (history->edit_count == history->edit_max){
undo_stack_grow_edits(general, history);
undo_stack_grow_edits(heap, history);
}
result = history->edits + (history->edit_count++);
*result = inv_step;
@ -281,7 +289,7 @@ file_post_history(General_Memory *general, Editing_File *file, Edit_Step step, b
internal void
file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step step, u8 *str, History_Mode history_mode){
if (!file->state.undo.undo.edits) return;
General_Memory *general = &mem->general;
Heap *heap = &mem->heap;
b32 can_merge = 0, do_merge = 0;
switch (step.type){
@ -295,16 +303,16 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step
}
if (history_mode != hist_forward){
file_post_history(general, file, step, do_merge, can_merge);
file_post_history(heap, file, step, do_merge, can_merge);
}
file_post_undo(general, file, step, do_merge, can_merge);
file_post_undo(heap, file, step, do_merge, can_merge);
}break;
case ED_REVERSE_NORMAL:
{
if (history_mode != hist_forward){
file_post_history(general, file, step, do_merge, can_merge);
file_post_history(heap, file, step, do_merge, can_merge);
}
undo_stack_pop(&file->state.undo.undo);
@ -349,10 +357,10 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step
++redo_end;
if (file->state.undo.redo.edit_count + steps_of_redo > file->state.undo.redo.edit_max)
undo_stack_grow_edits(general, &file->state.undo.redo);
undo_stack_grow_edits(heap, &file->state.undo.redo);
if (file->state.undo.redo.size + strings_of_redo > file->state.undo.redo.max)
undo_stack_grow_string(general, &file->state.undo.redo, strings_of_redo);
undo_stack_grow_string(heap, &file->state.undo.redo, strings_of_redo);
u8 *str_src = file->state.undo.history.strings + redo_end->edit.str_start;
u8 *str_dest_base = file->state.undo.redo.strings;
@ -398,9 +406,9 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step
case ED_UNDO:
{
if (history_mode != hist_forward){
file_post_history(general, file, step, do_merge, can_merge);
file_post_history(heap, file, step, do_merge, can_merge);
}
file_post_redo(general, file, step);
file_post_redo(heap, file, step);
undo_stack_pop(&file->state.undo.undo);
}break;
@ -410,10 +418,10 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step
if (step.edit.len == 1 && str && (can_merge || char_is_whitespace(*str))) do_merge = 1;
if (history_mode != hist_forward){
file_post_history(general, file, step, do_merge, can_merge);
file_post_history(heap, file, step, do_merge, can_merge);
}
file_post_undo(general, file, step, do_merge, can_merge);
file_post_undo(heap, file, step, do_merge, can_merge);
undo_stack_pop(&file->state.undo.redo);
}break;
}

View File

@ -20,7 +20,7 @@ view_get_map(View *view){
}
internal View_And_ID
live_set_alloc_view(General_Memory *general, Lifetime_Allocator *lifetime_allocator, Live_Views *live_set, Panel *panel){
live_set_alloc_view(Heap *heap, Lifetime_Allocator *lifetime_allocator, Live_Views *live_set, Panel *panel){
Assert(live_set->count < live_set->max);
++live_set->count;
@ -39,19 +39,19 @@ live_set_alloc_view(General_Memory *general, Lifetime_Allocator *lifetime_alloca
init_query_set(&result.view->transient.query_set);
dynamic_variables_block_init(general, &result.view->transient.dynamic_vars);
result.view->transient.lifetime_object = lifetime_alloc_object(general, lifetime_allocator, LifetimeObject_View, result.view);
dynamic_workspace_init(heap, &result.view->transient.dynamic_workspace);
result.view->transient.lifetime_object = lifetime_alloc_object(heap, lifetime_allocator, LifetimeObject_View, result.view);
return(result);
}
inline void
live_set_free_view(General_Memory *general, Lifetime_Allocator *lifetime_allocator, Live_Views *live_set, View *view){
live_set_free_view(Heap *heap, Lifetime_Allocator *lifetime_allocator, Live_Views *live_set, View *view){
Assert(live_set->count > 0);
--live_set->count;
if (view->transient.ui_control.items != 0){
general_memory_free(general, view->transient.ui_control.items);
heap_free(heap, view->transient.ui_control.items);
}
view->transient.next = live_set->free_sentinel.transient.next;
@ -60,8 +60,8 @@ live_set_free_view(General_Memory *general, Lifetime_Allocator *lifetime_allocat
view->transient.next->transient.prev = view;
view->transient.in_use = false;
dynamic_variables_block_free(general, &view->transient.dynamic_vars);
lifetime_free_object(general, lifetime_allocator, view->transient.lifetime_object);
dynamic_workspace_free(heap, &view->transient.dynamic_workspace);
lifetime_free_object(heap, lifetime_allocator, view->transient.lifetime_object);
}
////////////////////////////////

View File

@ -36,7 +36,7 @@ struct View_Transient{
b32 in_use;
File_Viewing_Data file_data;
Dynamic_Variable_Block dynamic_vars;
Dynamic_Workspace dynamic_workspace;
Lifetime_Object *lifetime_object;
i32_Rect file_region_prev;

View File

@ -66,11 +66,11 @@ working_set_extend_memory(Working_Set *working_set, Editing_File *new_space, i16
}
internal Editing_File*
working_set_alloc_always(Working_Set *working_set, General_Memory *general, Lifetime_Allocator *lifetime_allocator){
working_set_alloc_always(Working_Set *working_set, Heap *heap, Lifetime_Allocator *lifetime_allocator){
Editing_File *result = 0;
if (working_set->file_count == working_set->file_max && working_set->array_count < working_set->array_max){
i16 new_count = (i16)clamp_top(working_set->file_max, max_i16);
Editing_File *new_chunk = gen_array(general, Editing_File, new_count);
Editing_File *new_chunk = heap_array(heap, Editing_File, new_count);
working_set_extend_memory(working_set, new_chunk, new_count);
}
@ -88,8 +88,8 @@ working_set_alloc_always(Working_Set *working_set, General_Memory *general, Life
result->settings.minimum_base_display_width = working_set->default_minimum_base_display_width;
result->settings.wrap_indicator = WrapIndicator_Show_At_Wrap_Edge;
init_file_markers_state(&result->markers);
dynamic_variables_block_init(general, &result->dynamic_vars);
result->lifetime_object = lifetime_alloc_object(general, lifetime_allocator, LifetimeObject_File, result);
dynamic_workspace_init(heap, &result->dynamic_workspace);
result->lifetime_object = lifetime_alloc_object(heap, lifetime_allocator, LifetimeObject_File, result);
++working_set->file_count;
}
@ -97,13 +97,13 @@ working_set_alloc_always(Working_Set *working_set, General_Memory *general, Life
}
inline void
working_set_free_file(General_Memory *general, Lifetime_Allocator *lifetime_allocator, Working_Set *working_set, Editing_File *file){
working_set_free_file(Heap *heap, Lifetime_Allocator *lifetime_allocator, Working_Set *working_set, Editing_File *file){
if (working_set->sync_check_iter == &file->node){
working_set->sync_check_iter = working_set->sync_check_iter->next;
}
dynamic_variables_block_free(general, &file->dynamic_vars);
lifetime_free_object(general, lifetime_allocator, file->lifetime_object);
dynamic_workspace_free(heap, &file->dynamic_workspace);
lifetime_free_object(heap, lifetime_allocator, file->lifetime_object);
file->is_dummy = true;
dll_remove(&file->node);
@ -149,7 +149,7 @@ working_set_get_active_file(Working_Set *working_set, i32 id){
}
internal void
working_set_init(Working_Set *working_set, Partition *partition, General_Memory *general){
working_set_init(Working_Set *working_set, Partition *partition, Heap *heap){
i16 init_count = 16;
i16 array_init_count = 256;
@ -178,7 +178,7 @@ working_set_init(Working_Set *working_set, Partition *partition, General_Memory
i32 item_size = sizeof(File_Name_Entry);
i32 table_size = working_set->file_max;
i32 mem_size = table_required_mem_size(table_size, item_size);
void *mem = general_memory_allocate(general, mem_size);
void *mem = heap_allocate(heap, mem_size);
memset(mem, 0, mem_size);
table_init_memory(&working_set->canon_table, mem, table_size, item_size);
}
@ -188,23 +188,23 @@ working_set_init(Working_Set *working_set, Partition *partition, General_Memory
i32 item_size = sizeof(File_Name_Entry);
i32 table_size = working_set->file_max;
i32 mem_size = table_required_mem_size(table_size, item_size);
void *mem = general_memory_allocate(general, mem_size);
void *mem = heap_allocate(heap, mem_size);
memset(mem, 0, mem_size);
table_init_memory(&working_set->name_table, mem, table_size, item_size);
}
}
inline void
working_set__grow_if_needed(Table *table, General_Memory *general, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){
working_set__grow_if_needed(Table *table, Heap *heap, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){
if (table_at_capacity(table)){
Table btable = {0};
i32 new_max = table->max * 2;
i32 mem_size = table_required_mem_size(new_max, table->item_size);
void *mem = general_memory_allocate(general, mem_size);
void *mem = heap_allocate(heap, mem_size);
table_init_memory(&btable, mem, new_max, table->item_size);
table_clear(&btable);
table_rehash(table, &btable, 0, hash_func, comp_func);
general_memory_free(general, table->hash_array);
heap_free(heap, table->hash_array);
*table = btable;
}
}
@ -223,8 +223,8 @@ working_set_contains_basic(Working_Set *working_set, Table *table, String name){
}
internal b32
working_set_add_basic(General_Memory *general, Working_Set *working_set, Table *table, Editing_File *file, String name){
working_set__grow_if_needed(table, general, 0, tbl_string_hash, tbl_string_compare);
working_set_add_basic(Heap *heap, Working_Set *working_set, Table *table, Editing_File *file, String name){
working_set__grow_if_needed(table, heap, 0, tbl_string_hash, tbl_string_compare);
File_Name_Entry entry;
entry.name = name;
@ -245,8 +245,8 @@ working_set_contains_canon(Working_Set *working_set, String name){
}
internal b32
working_set_canon_add(General_Memory *general, Working_Set *working_set, Editing_File *file, String name){
b32 result = working_set_add_basic(general,working_set, &working_set->canon_table, file, name);
working_set_canon_add(Heap *heap, Working_Set *working_set, Editing_File *file, String name){
b32 result = working_set_add_basic(heap,working_set, &working_set->canon_table, file, name);
return(result);
}
@ -262,8 +262,8 @@ working_set_contains_name(Working_Set *working_set, String name){
}
internal b32
working_set_add_name(General_Memory *general, Working_Set *working_set, Editing_File *file, String name){
b32 result = working_set_add_basic(general, working_set, &working_set->name_table, file, name);
working_set_add_name(Heap *heap, Working_Set *working_set, Editing_File *file, String name){
b32 result = working_set_add_basic(heap, working_set, &working_set->name_table, file, name);
return(result);
}
@ -316,7 +316,7 @@ touch_file(Working_Set *working_set, Editing_File *file){
// TODO(allen): Bring the clipboard fully to the custom side.
internal String*
working_set_next_clipboard_string(General_Memory *general, Working_Set *working, i32 str_size){
working_set_next_clipboard_string(Heap *heap, Working_Set *working, i32 str_size){
i32 clipboard_current = working->clipboard_current;
if (working->clipboard_size == 0){
clipboard_current = 0;
@ -334,12 +334,14 @@ working_set_next_clipboard_string(General_Memory *general, Working_Set *working,
String *result = &working->clipboards[clipboard_current];
working->clipboard_current = clipboard_current;
working->clipboard_rolling = clipboard_current;
char *new_str;
char *new_str = 0;
if (result->str != 0){
new_str = (char*)general_memory_reallocate(general, result->str, result->size, str_size);
new_str = heap_array(heap, char, str_size);
memcpy(new_str, result->str, result->size);
heap_free(heap, result->str);
}
else{
new_str = (char*)general_memory_allocate(general, str_size+1);
new_str = (char*)heap_allocate(heap, str_size + 1);
}
// TODO(allen): What if new_str == 0?
*result = make_string_cap(new_str, 0, str_size);
@ -397,7 +399,7 @@ get_canon_name(System_Functions *system, String filename,
}
internal void
buffer_bind_file(System_Functions *system, General_Memory *general,
buffer_bind_file(System_Functions *system, Heap *heap,
Working_Set *working_set,
Editing_File *file, String canon_filename){
Assert(file->unique_name.name.size == 0);
@ -407,7 +409,7 @@ buffer_bind_file(System_Functions *system, General_Memory *general,
copy(&file->canon.name, canon_filename);
terminate_with_null(&file->canon.name);
system->add_listener(file->canon.name.str);
if (!working_set_canon_add(general, working_set, file, file->canon.name)){
if (!working_set_canon_add(heap, working_set, file, file->canon.name)){
InvalidCodePath;
}
}
@ -458,7 +460,7 @@ buffer_resolve_name_low_level(Working_Set *working_set, Editing_File_Name *name,
}
internal void
buffer_bind_name_low_level(General_Memory *general, Working_Set *working_set, Editing_File *file, String base_name, String name){
buffer_bind_name_low_level(Heap *heap, Working_Set *working_set, Editing_File *file, String base_name, String name){
Assert(file->base_name.name.size == 0);
Assert(file->unique_name.name.size == 0);
@ -472,7 +474,7 @@ buffer_bind_name_low_level(General_Memory *general, Working_Set *working_set, Ed
file->unique_name.name = make_fixed_width_string(file->unique_name.name_);
copy(&file->unique_name.name, new_name.name);
if (!working_set_add_name(general, working_set, file, file->unique_name.name)){
if (!working_set_add_name(heap, working_set, file, file->unique_name.name)){
InvalidCodePath;
}
}
@ -487,7 +489,7 @@ buffer_unbind_name_low_level(Working_Set *working_set, Editing_File *file){
}
internal void
buffer_bind_name(Models *models, General_Memory *general, Partition *scratch,
buffer_bind_name(Models *models, Heap *heap, Partition *scratch,
Working_Set *working_set,
Editing_File *file, String base_name){
Temp_Memory temp = begin_temp_memory(scratch);
@ -555,7 +557,7 @@ buffer_bind_name(Models *models, General_Memory *general, Partition *scratch,
Editing_File *file_ptr = conflict_file_ptrs[i];
Buffer_Name_Conflict_Entry *entry = &conflicts[i];
String unique_name = make_string(entry->unique_name_in_out, entry->unique_name_len_in_out);
buffer_bind_name_low_level(general, working_set, file_ptr, base_name, unique_name);
buffer_bind_name_low_level(heap, working_set, file_ptr, base_name, unique_name);
}
end_temp_memory(temp);
@ -576,12 +578,12 @@ open_file(System_Functions *system, Models *models, String filename){
Plat_Handle handle;
if (system->load_handle(canon_name.name.str, &handle)){
Mem_Options *mem = &models->mem;
General_Memory *general = &mem->general;
Heap *heap = &mem->heap;
Partition *part = &mem->part;
file = working_set_alloc_always(working_set, general, &models->lifetime_allocator);
buffer_bind_file(system, general, working_set, file, canon_name.name);
buffer_bind_name(models, general, part, working_set, file, front_of_directory(filename));
file = working_set_alloc_always(working_set, heap, &models->lifetime_allocator);
buffer_bind_file(system, heap, working_set, file, canon_name.name);
buffer_bind_name(models, heap, part, working_set, file, front_of_directory(filename));
Temp_Memory temp = begin_temp_memory(part);
@ -589,7 +591,7 @@ open_file(System_Functions *system, Models *models, String filename){
char *buffer = push_array(part, char, size);
b32 gen_buffer = false;
if (buffer == 0){
buffer = (char*)general_memory_allocate(general, size);
buffer = heap_array(heap, char, size);
Assert(buffer != 0);
gen_buffer = true;
}
@ -601,7 +603,7 @@ open_file(System_Functions *system, Models *models, String filename){
}
if (gen_buffer){
general_memory_free(general, buffer);
heap_free(heap, buffer);
}
end_temp_memory(temp);

View File

@ -33,7 +33,9 @@
# define FSTRING_IMPLEMENTATION
# include "4coder_lib/4coder_string.h"
# include "4coder_lib/4coder_mem.h"
# include "4coder_lib/4coder_arena.h"
# include "4coder_lib/4coder_arena.cpp"
# include "4coder_API/types.h"