introduced memory debugging mode, finished comment wrapping rule

master
Allen Webster 2016-10-22 11:30:25 -04:00
parent 6f64d7c12e
commit 43d6c29e8b
11 changed files with 513 additions and 319 deletions

View File

@ -146,6 +146,36 @@ general_sentinel_init(Bubble *bubble){
bubble->size = 0; bubble->size = 0;
} }
#define BUBBLE_MIN_SIZE 1024
static void
general_memory_attempt_split(General_Memory *general, Bubble *bubble, int32_t wanted_size){
int32_t 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 = (uint32_t)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 static void
general_memory_open(General_Memory *general, void *memory, int32_t size){ general_memory_open(General_Memory *general, void *memory, int32_t size){
general_sentinel_init(&general->sentinel); general_sentinel_init(&general->sentinel);
@ -188,21 +218,6 @@ static int32_t
general_memory_check(General_Memory *general){} general_memory_check(General_Memory *general){}
#endif #endif
#define BUBBLE_MIN_SIZE 1024
static void
general_memory_attempt_split(General_Memory *general, Bubble *bubble, int32_t wanted_size){
int32_t 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 = (uint32_t)MEM_BUBBLE_FLAG_INIT;
new_bubble->size = remaining_size - sizeof(Bubble);
insert_bubble(bubble, new_bubble);
insert_bubble2(&general->free_sentinel, new_bubble);
}
}
static void* static void*
general_memory_allocate(General_Memory *general, int32_t size){ general_memory_allocate(General_Memory *general, int32_t size){
void *result = 0; void *result = 0;
@ -224,20 +239,6 @@ general_memory_allocate(General_Memory *general, int32_t size){
return(result); return(result);
} }
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);
}
}
static void static void
general_memory_free(General_Memory *general, void *memory){ general_memory_free(General_Memory *general, void *memory){
Bubble *bubble = ((Bubble*)memory) - 1; Bubble *bubble = ((Bubble*)memory) - 1;
@ -280,11 +281,5 @@ general_memory_reallocate_nocopy(General_Memory *general, void *old, int32_t siz
return(result); return(result);
} }
#define reset_temp_memory end_temp_memory
#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)
#endif #endif

View File

@ -123,7 +123,6 @@ ENUM(uint32_t, Cpp_Token_Type){
CPP_TOKEN_ARROW = 62, CPP_TOKEN_ARROW = 62,
// NOTE(allen): Precedence 3, RtoL // NOTE(allen): Precedence 3, RtoL
/* DOC(This token is for parser use, it is not output by the lexer.) */ /* DOC(This token is for parser use, it is not output by the lexer.) */
CPP_TOKEN_PREINC = 63, CPP_TOKEN_PREINC = 63,
/* DOC(This token is for parser use, it is not output by the lexer.) */ /* DOC(This token is for parser use, it is not output by the lexer.) */

29
4ed.cpp
View File

@ -273,7 +273,7 @@ panel_make_empty(System_Functions *system, App_Vars *vars, Panel *panel){
View_And_ID new_view; View_And_ID new_view;
Assert(panel->view == 0); Assert(panel->view == 0);
new_view = live_set_alloc_view(&vars->live_set, panel, models); new_view = live_set_alloc_view(system, &vars->live_set, panel, models);
view_set_file(new_view.view, models->scratch_buffer, models); view_set_file(new_view.view, models->scratch_buffer, models);
new_view.view->map = get_map(models, mapid_file); new_view.view->map = get_map(models, mapid_file);
@ -493,9 +493,7 @@ COMMAND_DECL(toggle_tokens){
} }
internal void internal void
case_change_range(System_Functions *system, case_change_range(System_Functions *system, Mem_Options *mem, View *view, Editing_File *file, u8 a, u8 z, u8 char_delta){
Mem_Options *mem, View *view, Editing_File *file,
u8 a, u8 z, u8 char_delta){
#if BUFFER_EXPERIMENT_SCALPEL <= 0 #if BUFFER_EXPERIMENT_SCALPEL <= 0
Range range = make_range(view->edit_pos->cursor.pos, view->edit_pos->mark); Range range = make_range(view->edit_pos->cursor.pos, view->edit_pos->mark);
if (range.start < range.end){ if (range.start < range.end){
@ -505,10 +503,11 @@ case_change_range(System_Functions *system,
step.edit.end = range.end; step.edit.end = range.end;
step.edit.len = range.end - range.start; step.edit.len = range.end - range.start;
if (file->state.still_lexing) if (file->state.still_lexing){
system->cancel_job(BACKGROUND_THREADS, file->state.lex_job); system->cancel_job(BACKGROUND_THREADS, file->state.lex_job);
}
file_update_history_before_edit(mem, file, step, 0, hist_normal); file_update_history_before_edit(system, mem, file, step, 0, hist_normal);
u8 *data = (u8*)file->state.buffer.data; u8 *data = (u8*)file->state.buffer.data;
for (i32 i = range.start; i < range.end; ++i){ for (i32 i = range.start; i < range.end; ++i){
@ -1304,14 +1303,14 @@ app_vars_zero(){
} }
internal App_Vars* internal App_Vars*
app_setup_memory(Application_Memory *memory){ app_setup_memory(System_Functions *system, Application_Memory *memory){
Partition _partition = make_part(memory->vars_memory, memory->vars_memory_size); Partition _partition = make_part(memory->vars_memory, memory->vars_memory_size);
App_Vars *vars = push_struct(&_partition, App_Vars); App_Vars *vars = push_struct(&_partition, App_Vars);
Assert(vars); Assert(vars);
*vars = app_vars_zero(); *vars = app_vars_zero();
vars->models.mem.part = _partition; vars->models.mem.part = _partition;
general_memory_open(&vars->models.mem.general, memory->target_memory, memory->target_memory_size); general_memory_open(system, &vars->models.mem.general, memory->target_memory, memory->target_memory_size);
return(vars); return(vars);
} }
@ -1324,7 +1323,7 @@ app_settings_zero(){
App_Read_Command_Line_Sig(app_read_command_line){ App_Read_Command_Line_Sig(app_read_command_line){
i32 out_size = 0; i32 out_size = 0;
App_Vars *vars = app_setup_memory(memory); App_Vars *vars = app_setup_memory(system, memory);
App_Settings *settings = &vars->models.settings; App_Settings *settings = &vars->models.settings;
*settings = app_settings_zero(); *settings = app_settings_zero();
@ -1658,7 +1657,7 @@ App_Init_Sig(app_init){
} }
// NOTE(allen): file setup // NOTE(allen): file setup
working_set_init(&models->working_set, partition, &vars->models.mem.general); working_set_init(system, &models->working_set, partition, &vars->models.mem.general);
models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH; models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH;
// NOTE(allen): clipboard setup // NOTE(allen): clipboard setup
@ -1669,7 +1668,7 @@ App_Init_Sig(app_init){
// TODO(allen): more robust allocation solution for the clipboard // TODO(allen): more robust allocation solution for the clipboard
if (clipboard.str){ 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(system, &models->mem.general, &models->working_set, clipboard.size);
copy_ss(dest, make_string((char*)clipboard.str, clipboard.size)); copy_ss(dest, make_string((char*)clipboard.str, clipboard.size));
} }
@ -1706,8 +1705,8 @@ App_Init_Sig(app_init){
}; };
for (i32 i = 0; i < ArrayCount(init_files); ++i){ for (i32 i = 0; i < ArrayCount(init_files); ++i){
Editing_File *file = working_set_alloc_always(&models->working_set, general); Editing_File *file = working_set_alloc_always(system, &models->working_set, general);
buffer_bind_name(general, &models->working_set, file, init_files[i].name); buffer_bind_name(system, general, &models->working_set, file, init_files[i].name);
switch (init_files[i].type){ switch (init_files[i].type){
case 0: init_normal_file(system, models, file, 0, 0); break; case 0: init_normal_file(system, models, file, 0, 0); break;
@ -1804,9 +1803,7 @@ App_Step_Sig(app_step){
if (clipboard.str){ if (clipboard.str){
String *dest = String *dest =
working_set_next_clipboard_string(&models->mem.general, working_set_next_clipboard_string(system, &models->mem.general, &models->working_set, clipboard.size);
&models->working_set,
clipboard.size);
dest->size = eol_convert_in(dest->str, clipboard.str, clipboard.size); dest->size = eol_convert_in(dest->str, clipboard.str, clipboard.size);
} }

View File

@ -251,7 +251,7 @@ DOC_SEE(Command_Line_Input_Flag)
} }
} }
else if (buffer.name){ else if (buffer.name){
file = working_set_alloc_always(working_set, general); file = working_set_alloc_always(system, working_set, general);
if (file == 0){ if (file == 0){
append_ss(&feedback_str, append_ss(&feedback_str,
make_lit_string("ERROR: unable to allocate a new buffer\n")); make_lit_string("ERROR: unable to allocate a new buffer\n"));
@ -261,7 +261,7 @@ DOC_SEE(Command_Line_Input_Flag)
} }
String name = make_string_terminated(part, buffer.name, buffer.name_len); String name = make_string_terminated(part, buffer.name, buffer.name_len);
buffer_bind_name(general, working_set, file, name); buffer_bind_name(system, general, working_set, file, name);
init_read_only_file(system, models, file); init_read_only_file(system, models, file);
} }
@ -372,7 +372,7 @@ DOC_SEE(The_4coder_Clipboard)
General_Memory *general = &models->mem.general; General_Memory *general = &models->mem.general;
Working_Set *working = &models->working_set; Working_Set *working = &models->working_set;
String *dest = working_set_next_clipboard_string(general, working, len); String *dest = working_set_next_clipboard_string(system, general, working, len);
copy_ss(dest, make_string(str, len)); copy_ss(dest, make_string(str, len));
system->post_clipboard(*dest); system->post_clipboard(*dest);
} }
@ -681,6 +681,7 @@ DOC_SEE(Buffer_Batch_Edit_Type)
Mem_Options *mem = &models->mem; Mem_Options *mem = &models->mem;
Partition *part = &mem->part; Partition *part = &mem->part;
Editing_File *file = imp_get_file(cmd, buffer); Editing_File *file = imp_get_file(cmd, buffer);
System_Functions *system = cmd->system;
bool32 result = false; bool32 result = false;
@ -694,12 +695,9 @@ DOC_SEE(Buffer_Batch_Edit_Type)
int32_t inv_str_max = part->max - part->pos; int32_t inv_str_max = part->max - part->pos;
Edit_Spec spec = Edit_Spec spec =
file_compute_edit(mem, file, file_compute_edit(system, mem, file, edits, str, str_len, inverse_edits, inv_str, inv_str_max, edit_count, type);
edits, str, str_len,
inverse_edits, inv_str, inv_str_max,
edit_count, type);
file_do_batch_edit(cmd->system, models, file, spec, hist_normal, type); file_do_batch_edit(system, models, file, spec, hist_normal, type);
end_temp_memory(temp); end_temp_memory(temp);
} }
@ -780,8 +778,7 @@ DOC_SEE(Buffer_Setting_ID)
if (new_value != file->settings.display_width){ if (new_value != file->settings.display_width){
i16 font_id = file->settings.font_id; i16 font_id = file->settings.font_id;
Render_Font *font = get_font_info(models->font_set, font_id)->font; Render_Font *font = get_font_info(models->font_set, font_id)->font;
file_set_display_width_and_fix_cursor(models, file, new_value, file_set_display_width_and_fix_cursor(system, models, file, new_value, (f32)font->height, font->advance_data);
(f32)font->height, font->advance_data);
} }
}break; }break;
@ -855,9 +852,9 @@ DOC_SEE(Buffer_Setting_ID)
i16 font_id = file->settings.font_id; i16 font_id = file->settings.font_id;
Render_Font *font = get_font_info(models->font_set, font_id)->font; Render_Font *font = get_font_info(models->font_set, font_id)->font;
file_allocate_character_starts_as_needed(&models->mem.general, file); file_allocate_character_starts_as_needed(system, &models->mem.general, file);
buffer_measure_character_starts(&file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white); buffer_measure_character_starts(&file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
file_measure_wraps(models, file, (f32)font->height, font->advance_data); file_measure_wraps(system, models, file, (f32)font->height, font->advance_data);
file_update_cursor_positions(models, file); file_update_cursor_positions(models, file);
} }
}break; }break;
@ -1008,31 +1005,31 @@ End_Buffer_Creation(Application_Links *app, Buffer_Creation_Data *data){
char *buffer = push_array(part, char, size); char *buffer = push_array(part, char, size);
if (buffer == 0){ if (buffer == 0){
buffer = (char*)general_memory_allocate(general, size); buffer = (char*)general_memory_allocate(system, general, size);
Assert(buffer != 0); Assert(buffer != 0);
in_general_mem = 1; in_general_mem = 1;
} }
if (system->load_file(handle, buffer, size)){ if (system->load_file(handle, buffer, size)){
file = working_set_alloc_always(working_set, general); file = working_set_alloc_always(system, working_set, general);
if (file){ if (file){
buffer_bind_file(system, general, working_set, file, canon.name); buffer_bind_file(system, general, working_set, file, canon.name);
buffer_bind_name(general, working_set, file, fname); buffer_bind_name(system, general, working_set, file, fname);
init_normal_file(system, models, file, buffer, size); init_normal_file(system, models, file, buffer, size);
fill_buffer_summary(&result, file, cmd); fill_buffer_summary(&result, file, cmd);
} }
} }
if (in_general_mem){ if (in_general_mem){
general_memory_free(general, buffer); general_memory_free(system, general, buffer);
} }
system->load_close(handle); system->load_close(handle);
} }
else if (!(flags & BufferCreate_NeverNew)){ else if (!(flags & BufferCreate_NeverNew)){
file = working_set_alloc_always(working_set, general); file = working_set_alloc_always(system, working_set, general);
if (file){ if (file){
buffer_bind_name(general, working_set, file, fname); buffer_bind_name(system, general, working_set, file, fname);
init_normal_file(system, models, file, 0, 0); init_normal_file(system, models, file, 0, 0);
fill_buffer_summary(&result, file, cmd); fill_buffer_summary(&result, file, cmd);
} }
@ -1116,31 +1113,31 @@ DOC_SEE(Buffer_Create_Flag)
char *buffer = push_array(part, char, size); char *buffer = push_array(part, char, size);
if (buffer == 0){ if (buffer == 0){
buffer = (char*)general_memory_allocate(general, size); buffer = (char*)general_memory_allocate(system, general, size);
Assert(buffer != 0); Assert(buffer != 0);
in_general_mem = 1; in_general_mem = 1;
} }
if (system->load_file(handle, buffer, size)){ if (system->load_file(handle, buffer, size)){
file = working_set_alloc_always(working_set, general); file = working_set_alloc_always(system, working_set, general);
if (file){ if (file){
buffer_bind_file(system, general, working_set, file, canon.name); buffer_bind_file(system, general, working_set, file, canon.name);
buffer_bind_name(general, working_set, file, fname); buffer_bind_name(system, general, working_set, file, fname);
init_normal_file(system, models, file, buffer, size); init_normal_file(system, models, file, buffer, size);
fill_buffer_summary(&result, file, cmd); fill_buffer_summary(&result, file, cmd);
} }
} }
if (in_general_mem){ if (in_general_mem){
general_memory_free(general, buffer); general_memory_free(system, general, buffer);
} }
system->load_close(handle); system->load_close(handle);
} }
else if (!(flags & BufferCreate_NeverNew)){ else if (!(flags & BufferCreate_NeverNew)){
file = working_set_alloc_always(working_set, general); file = working_set_alloc_always(system, working_set, general);
if (file){ if (file){
buffer_bind_name(general, working_set, file, fname); buffer_bind_name(system, general, working_set, file, fname);
init_normal_file(system, models, file, 0, 0); init_normal_file(system, models, file, 0, 0);
fill_buffer_summary(&result, file, cmd); fill_buffer_summary(&result, file, cmd);
} }

View File

@ -25,6 +25,7 @@
#include "4ed_rendering.h" #include "4ed_rendering.h"
#include "4ed.h" #include "4ed.h"
#include "4ed_mem.h"
#define FCPP_FORBID_MALLOC #define FCPP_FORBID_MALLOC
#include "4cpp_lexer.h" #include "4cpp_lexer.h"

View File

@ -459,7 +459,7 @@ working_set_alloc(Working_Set *working_set){
} }
internal Editing_File* internal Editing_File*
working_set_alloc_always(Working_Set *working_set, General_Memory *general){ working_set_alloc_always(System_Functions *system, Working_Set *working_set, General_Memory *general){
Editing_File *result = 0; Editing_File *result = 0;
Editing_File *new_chunk; Editing_File *new_chunk;
i32 full_new_count = working_set->file_max; i32 full_new_count = working_set->file_max;
@ -468,9 +468,8 @@ working_set_alloc_always(Working_Set *working_set, General_Memory *general){
if (full_new_count > max_i16) new_count = max_i16; if (full_new_count > max_i16) new_count = max_i16;
else new_count = (i16)full_new_count; else new_count = (i16)full_new_count;
if (working_set->file_count == working_set->file_max && if (working_set->file_count == working_set->file_max &&working_set->array_count < working_set->array_max){
working_set->array_count < working_set->array_max){ new_chunk = gen_array(system, general, Editing_File, new_count);
new_chunk = gen_array(general, Editing_File, new_count);
working_set_extend_memory(working_set, new_chunk, new_count); working_set_extend_memory(working_set, new_chunk, new_count);
} }
result = working_set_alloc(working_set); result = working_set_alloc(working_set);
@ -529,7 +528,7 @@ working_set_get_active_file(Working_Set *working_set, i32 id){
} }
internal void internal void
working_set_init(Working_Set *working_set, Partition *partition, General_Memory *general){ working_set_init(System_Functions *system, Working_Set *working_set, Partition *partition, General_Memory *general){
i16 init_count = 16; i16 init_count = 16;
i16 array_init_count = 256; i16 array_init_count = 256;
@ -555,7 +554,7 @@ working_set_init(Working_Set *working_set, Partition *partition, General_Memory
i32 item_size = sizeof(File_Name_Entry); i32 item_size = sizeof(File_Name_Entry);
i32 table_size = working_set->file_max; i32 table_size = working_set->file_max;
i32 mem_size = table_required_mem_size(table_size, item_size); i32 mem_size = table_required_mem_size(table_size, item_size);
void *mem = general_memory_allocate(general, mem_size); void *mem = general_memory_allocate(system, general, mem_size);
memset(mem, 0, mem_size); memset(mem, 0, mem_size);
table_init_memory(&working_set->canon_table, mem, table_size, item_size); table_init_memory(&working_set->canon_table, mem, table_size, item_size);
} }
@ -565,23 +564,23 @@ working_set_init(Working_Set *working_set, Partition *partition, General_Memory
i32 item_size = sizeof(File_Name_Entry); i32 item_size = sizeof(File_Name_Entry);
i32 table_size = working_set->file_max; i32 table_size = working_set->file_max;
i32 mem_size = table_required_mem_size(table_size, item_size); i32 mem_size = table_required_mem_size(table_size, item_size);
void *mem = general_memory_allocate(general, mem_size); void *mem = general_memory_allocate(system, general, mem_size);
memset(mem, 0, mem_size); memset(mem, 0, mem_size);
table_init_memory(&working_set->name_table, mem, table_size, item_size); table_init_memory(&working_set->name_table, mem, table_size, item_size);
} }
} }
inline void 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(System_Functions *system, Table *table, General_Memory *general, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){
if (table_at_capacity(table)){ if (table_at_capacity(table)){
Table btable = {0}; Table btable = {0};
i32 new_max = table->max * 2; i32 new_max = table->max * 2;
i32 mem_size = table_required_mem_size(new_max, table->item_size); i32 mem_size = table_required_mem_size(new_max, table->item_size);
void *mem = general_memory_allocate(general, mem_size); void *mem = general_memory_allocate(system, general, mem_size);
table_init_memory(&btable, mem, new_max, table->item_size); table_init_memory(&btable, mem, new_max, table->item_size);
table_clear(&btable); table_clear(&btable);
table_rehash(table, &btable, 0, hash_func, comp_func); table_rehash(table, &btable, 0, hash_func, comp_func);
general_memory_free(general, table->hash_array); general_memory_free(system, general, table->hash_array);
*table = btable; *table = btable;
} }
} }
@ -600,10 +599,8 @@ working_set_contains_basic(Working_Set *working_set, Table *table, String name){
} }
internal b32 internal b32
working_set_add_basic(General_Memory *general, Working_Set *working_set, Table *table, working_set_add_basic(System_Functions *system, General_Memory *general, Working_Set *working_set, Table *table, Editing_File *file, String name){
Editing_File *file, String name){ working_set__grow_if_needed(system, table, general, 0, tbl_string_hash, tbl_string_compare);
working_set__grow_if_needed(table, general,
0, tbl_string_hash, tbl_string_compare);
File_Name_Entry entry; File_Name_Entry entry;
entry.name = name; entry.name = name;
@ -625,9 +622,9 @@ working_set_canon_contains(Working_Set *working_set, String name){
} }
internal b32 internal b32
working_set_canon_add(General_Memory *general, Working_Set *working_set, working_set_canon_add(System_Functions *system, General_Memory *general, Working_Set *working_set,
Editing_File *file, String name){ Editing_File *file, String name){
b32 result = working_set_add_basic(general, working_set, &working_set->canon_table, file, name); b32 result = working_set_add_basic(system, general,working_set, &working_set->canon_table, file, name);
return(result); return(result);
} }
@ -644,9 +641,9 @@ working_set_name_contains(Working_Set *working_set, String name){
} }
internal b32 internal b32
working_set_name_add(General_Memory *general, Working_Set *working_set, working_set_name_add(System_Functions *system, General_Memory *general, Working_Set *working_set,
Editing_File *file, String name){ Editing_File *file, String name){
b32 result = working_set_add_basic(general, working_set, &working_set->name_table, file, name); b32 result = working_set_add_basic(system, general, working_set, &working_set->name_table, file, name);
return(result); return(result);
} }
@ -939,7 +936,7 @@ buffer_bind_file(System_Functions *system, General_Memory *general, Working_Set
copy_ss(&file->canon.name, canon_filename); copy_ss(&file->canon.name, canon_filename);
terminate_with_null(&file->canon.name); terminate_with_null(&file->canon.name);
system->add_listener(file->canon.name_); system->add_listener(file->canon.name_);
b32 result = working_set_canon_add(general, working_set, file, file->canon.name); b32 result = working_set_canon_add(system, general, working_set, file, file->canon.name);
Assert(result); AllowLocal(result); Assert(result); AllowLocal(result);
} }
@ -956,7 +953,7 @@ buffer_unbind_file(System_Functions *system, Working_Set *working_set, Editing_F
} }
internal void internal void
buffer_bind_name(General_Memory *general, Working_Set *working_set, buffer_bind_name(System_Functions *system, General_Memory *general, Working_Set *working_set,
Editing_File *file, String filename){ Editing_File *file, String filename){
Assert(file->name.live_name.size == 0 && Assert(file->name.live_name.size == 0 &&
file->name.source_path.size == 0 && file->name.source_path.size == 0 &&
@ -971,7 +968,7 @@ buffer_bind_name(General_Memory *general, Working_Set *working_set,
copy_ss(&file->name.source_path, new_name.source_path); copy_ss(&file->name.source_path, new_name.source_path);
copy_ss(&file->name.extension, new_name.extension); copy_ss(&file->name.extension, new_name.extension);
b32 result = working_set_name_add(general, working_set, file, file->name.live_name); b32 result = working_set_name_add(system, general, working_set, file, file->name.live_name);
Assert(result); AllowLocal(result); Assert(result); AllowLocal(result);
} }

File diff suppressed because it is too large Load Diff

107
4ed_mem.h Normal file
View File

@ -0,0 +1,107 @@
#ifndef FED_MEM_H
#define FED_MEM_H
#include "4coder_mem.h"
#define MEMORY_DEBUG
static void
general_memory_open(System_Functions *system, General_Memory *general, void *memory, int32_t size){
#if defined(MEMORY_DEBUG)
general_memory_open(general, memory, size);
#else
general_memory_open(general, memory, size);
#endif
}
#if defined(Assert) && !defined(MEMORY_DEBUG)
static int32_t
general_memory_check(System_Functions *system, 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 int32_t
general_memory_check(System_Functions *system, General_Memory *general){return(1);}
#endif
#define OS_PAGE_SIZE 4096
static void*
general_memory_allocate(System_Functions *system, General_Memory *general, int32_t size){
#if defined(MEMORY_DEBUG)
{
persist u32 round_val = OS_PAGE_SIZE-1;
size = (size + round_val) & (~round_val);
void *result = system->memory_allocate(0, size + OS_PAGE_SIZE);
system->memory_set_protection(0, (u8*)result + size, OS_PAGE_SIZE, 0);
return(result);
}
#else
return general_memory_allocate(general, memory, size);
#endif
}
static void
general_memory_free(System_Functions *system, General_Memory *general, void *memory){
#if defined(MEMORY_DEBUG)
{
system->memory_free(0, memory, 0);
}
#else
return general_memory_free(general, memory, size);
#endif
}
static void*
general_memory_reallocate(System_Functions *system, General_Memory *general, void *old, int32_t old_size, int32_t size){
#if defined(MEMORY_DEBUG)
{
void *result = general_memory_allocate(system, general, size);
memcpy(result, old, old_size);
general_memory_free(system, general, old);
return(result);
}
#else
return general_memory_reallocate(general, memory, size);
#endif
}
inline void*
general_memory_reallocate_nocopy(System_Functions *system, General_Memory *general, void *old, int32_t size){
#if defined(MEMORY_DEBUG)
{
general_memory_free(system, general, old);
return general_memory_allocate(system, general, size);
}
#else
return general_memory_reallocate_nocopy(general, memory, size);
#endif
}
#define reset_temp_memory end_temp_memory
#define gen_struct(s, g, T) (T*)general_memory_allocate(s, g, sizeof(T), 0)
#define gen_array(s, g, T, size) (T*)general_memory_allocate(s, g, sizeof(T)*(size))
#define gen_block(s, g, size) general_memory_open(s, g, size, 0)
#endif

View File

@ -175,7 +175,7 @@
; [X] handle square brackets ; [X] handle square brackets
; [X] smarter wrap rule ; [X] smarter wrap rule
; [X] handle unclosed statements ; [X] handle unclosed statements
; [+] wrapped line indication ; [X] wrapped line indication
; [] special indent rules in preprocessor body ; [] special indent rules in preprocessor body
; [] handle comments ; [] handle comments
; [] additional width for nesting? ; [] additional width for nesting?
@ -289,6 +289,8 @@
; [] 4edT thing ; [] 4edT thing
; [] console emulator ; [] console emulator
; ;
; [] 10 GB text file
;
; INTERNAL TODOS ; INTERNAL TODOS
; [X] switch building non-extensible version by statically linking to custom.cpp ; [X] switch building non-extensible version by statically linking to custom.cpp

View File

@ -126,6 +126,10 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Buffer_Type *buffer){
state->count = (i32)(start_ptr - buffer->line_starts); state->count = (i32)(start_ptr - buffer->line_starts);
state->start = start; state->start = start;
if (!result){
buffer->line_count = state->count;
}
return(result); return(result);
} }

View File

@ -12,7 +12,8 @@ as this is the only one that will be used for generating headers and docs.
#define API_EXPORT #define API_EXPORT
API_EXPORT void* API_EXPORT void*
Memory_Allocate(Application_Links *app, int32_t size)/* Memory_Allocate(Application_Links *app, int32_t size)
/*
DOC_PARAM(size, The size in bytes of the block that should be returned.) DOC_PARAM(size, The size in bytes of the block that should be returned.)
DOC(This calls to a low level OS allocator which means it is best used DOC(This calls to a low level OS allocator which means it is best used
for infrequent, large allocations. The size of the block must be remembered for infrequent, large allocations. The size of the block must be remembered
@ -24,7 +25,8 @@ DOC_SEE(memory_free)
} }
API_EXPORT bool32 API_EXPORT bool32
Memory_Set_Protection(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags)/* Memory_Set_Protection(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags)
/*
DOC_PARAM(ptr, The base of the block on which to set memory protection flags.) DOC_PARAM(ptr, The base of the block on which to set memory protection flags.)
DOC_PARAM(size, The size that was originally used to allocate this block.) DOC_PARAM(size, The size that was originally used to allocate this block.)
DOC_PARAM(flags, The new memory protection flags.) DOC_PARAM(flags, The new memory protection flags.)
@ -40,21 +42,17 @@ DOC_SEE(Memory_Protect_Flags)
flags = flags & 0x7; flags = flags & 0x7;
switch (flags){ switch (flags){
case 0: case 0: protect = PAGE_NOACCESS; break;
protect = PAGE_NOACCESS; break;
case MemProtect_Read: case MemProtect_Read: protect = PAGE_READONLY; break;
protect = PAGE_READONLY; break;
case MemProtect_Write: case MemProtect_Write:
case MemProtect_Read|MemProtect_Write: case MemProtect_Read|MemProtect_Write:
protect = PAGE_READWRITE; break; protect = PAGE_READWRITE; break;
case MemProtect_Execute: case MemProtect_Execute: protect = PAGE_EXECUTE; break;
protect = PAGE_EXECUTE; break;
case MemProtect_Execute|MemProtect_Read: case MemProtect_Execute|MemProtect_Read: protect = PAGE_EXECUTE_READ; break;
protect = PAGE_EXECUTE_READ; break;
case MemProtect_Execute|MemProtect_Write: case MemProtect_Execute|MemProtect_Write:
case MemProtect_Execute|MemProtect_Write|MemProtect_Read: case MemProtect_Execute|MemProtect_Write|MemProtect_Read: