From 1a987c67816bb79a4ad134c459b6c9c2645dea56 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 19 Sep 2016 10:41:11 -0400 Subject: [PATCH] fixed bug with the parallel lexing routine not using the gap buffer --- 4cpp_lexer.h | 3 +- 4ed_file_view.cpp | 32 +++- TODO.txt | 6 +- buffer/4coder_buffer_abstract.cpp | 286 +++++++++++++++--------------- buffer/4coder_gap_buffer.cpp | 124 +++++++------ buffer/4coder_shared.cpp | 136 +++++++------- 6 files changed, 301 insertions(+), 286 deletions(-) diff --git a/4cpp_lexer.h b/4cpp_lexer.h index a13f8774..e6f28b56 100644 --- a/4cpp_lexer.h +++ b/4cpp_lexer.h @@ -1151,7 +1151,8 @@ cpp_get_relex_range(Cpp_Token_Array *array, int32_t start_pos, int32_t end_pos){ } FCPP_LINK Cpp_Relex_Data -cpp_relex_init(Cpp_Token_Array *array, int32_t start_pos, int32_t end_pos, int32_t character_shift_amount, char *spare){ +cpp_relex_init(Cpp_Token_Array *array, int32_t start_pos, int32_t end_pos, int32_t character_shift_amount, char *spare) +{ Cpp_Relex_Data state = {0}; Cpp_Relex_Range range = cpp_get_relex_range(array, start_pos, end_pos); diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 8460db63..5293b65f 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -1122,8 +1122,8 @@ Job_Callback_Sig(job_full_lex){ Editing_File *file = (Editing_File*)data[0]; General_Memory *general = (General_Memory*)data[1]; - char *text_data = file->state.buffer.data; - i32 text_size = buffer_size(&file->state.buffer); + Buffer_Type *buffer = &file->state.buffer; + i32 text_size = buffer_size(buffer); i32 buffer_size = (text_size + 3)&(~3); @@ -1142,12 +1142,32 @@ Job_Callback_Sig(job_full_lex){ Cpp_Lex_Data lex = cpp_lex_data_init(tb); + // TODO(allen): deduplicate this against relex + char *chunks[3]; + i32 chunk_sizes[3]; + + chunks[0] = buffer->data; + chunk_sizes[0] = buffer->size1; + + chunks[1] = buffer->data + buffer->size1 + buffer->gap_size; + chunk_sizes[1] = buffer->size2; + + chunks[2] = 0; + chunk_sizes[2] = 0; + + i32 chunk_index = 0; + do{ + char *chunk = chunks[chunk_index]; + i32 chunk_size = chunk_sizes[chunk_index]; + i32 result = - cpp_lex_step(&lex, text_data, text_size, text_size, &tokens, 2048); + cpp_lex_step(&lex, chunk, chunk_size, text_size, &tokens, 2048); switch (result){ - case LexResult_NeedChunk: Assert(!"Invalid Path"); break; + case LexResult_NeedChunk: + ++chunk_index; + break; case LexResult_NeedTokenMemory: if (system->check_cancel(thread)){ @@ -1290,10 +1310,10 @@ file_relex_parallel(System_Functions *system, chunks[2] = 0; chunk_sizes[2] = 0; - int32_t chunk_index = 0; + i32 chunk_index = 0; char *chunk = chunks[chunk_index]; - int32_t chunk_size = chunk_sizes[chunk_index]; + i32 chunk_size = chunk_sizes[chunk_index]; while (!cpp_relex_is_start_chunk(&state, chunk, chunk_size)){ ++chunk_index; diff --git a/TODO.txt b/TODO.txt index 2c67a6e7..47791b50 100644 --- a/TODO.txt +++ b/TODO.txt @@ -152,9 +152,9 @@ ; [] option to not open *messages* every startup ; ; [] query buffer font info -; [] break buffer name ties by adding parent directories instead of <#> +; [] option to break buffer name ties by adding parent directories instead of <#> ; [] undo groups -; [] cursor/scroll grouping +; [] cursor/scroll groups ; [] allow for arbitrary wrap positions independent of view width ; [] word level wrapping ~ temporary measure really want to have totally formatted code presentation ; [] double binding warnings @@ -171,8 +171,8 @@ ; buffer behavior cleanup ; [X] show all characters as \# if they can't be rendered -; [] binary buffer mode ; [] get the navigation working correctly around multi-glyph characters +; [] binary buffer mode ; [] support full length unicode file names ; meta programming system diff --git a/buffer/4coder_buffer_abstract.cpp b/buffer/4coder_buffer_abstract.cpp index cc89a2e0..16b79e25 100644 --- a/buffer/4coder_buffer_abstract.cpp +++ b/buffer/4coder_buffer_abstract.cpp @@ -1,11 +1,11 @@ -/* +/* * Mr. 4th Dimention - Allen Webster - * Four Tech * - * public domain -- no warranty is offered or implied; use this code at your own risk - * * 24.10.2015 - * + * + * Buffer features based on the stringify loop, + * and other abstract buffer features. + * */ // TOP @@ -15,7 +15,7 @@ #define Buffer_Backify_Type cat_4tech(Buffer_Type, _Backify_Loop) inline_4tech void -buffer_stringify(Buffer_Type *buffer, int start, int end, char *out){ +buffer_stringify(Buffer_Type *buffer, i32 start, i32 end, char *out){ for (Buffer_Stringify_Type loop = buffer_stringify_loop(buffer, start, end); buffer_stringify_good(&loop); buffer_stringify_next(&loop)){ @@ -24,10 +24,10 @@ buffer_stringify(Buffer_Type *buffer, int start, int end, char *out){ } } -internal_4tech int -buffer_convert_out(Buffer_Type *buffer, char *dest, int max){ +internal_4tech i32 +buffer_convert_out(Buffer_Type *buffer, char *dest, i32 max){ Buffer_Stringify_Type loop; - int size, out_size, pos, result; + i32 size, out_size, pos, result; size = buffer_size(buffer); assert_4tech(size + buffer->line_count < max); @@ -44,11 +44,11 @@ buffer_convert_out(Buffer_Type *buffer, char *dest, int max){ return(pos); } -internal_4tech int -buffer_count_newlines(Buffer_Type *buffer, int start, int end){ +internal_4tech i32 +buffer_count_newlines(Buffer_Type *buffer, i32 start, i32 end){ Buffer_Stringify_Type loop; - int i; - int count; + i32 i; + i32 count; assert_4tech(0 <= start); assert_4tech(start <= end); @@ -69,25 +69,25 @@ buffer_count_newlines(Buffer_Type *buffer, int start, int end){ #ifndef NON_ABSTRACT_4TECH typedef struct Buffer_Measure_Starts{ - int i; - int count; - int start; - float width; + i32 i; + i32 count; + i32 start; + f32 width; } Buffer_Measure_Starts; #endif -internal_4tech int -buffer_measure_starts_widths_(Buffer_Measure_Starts *state, Buffer_Type *buffer, float *advance_data){ +internal_4tech i32 +buffer_measure_starts_widths_(Buffer_Measure_Starts *state, Buffer_Type *buffer, f32 *advance_data){ Buffer_Stringify_Type loop; - int *start_ptr, *start_end; - float *width_ptr; - debug_4tech(int widths_max); - debug_4tech(int max); + i32 *start_ptr, *start_end; + f32 *width_ptr; + debug_4tech(i32 widths_max); + debug_4tech(i32 max); char *data; - int size, end; - float width; - int start, i; - int result; + i32 size, end; + f32 width; + i32 start, i; + i32 result; char ch; size = buffer_size(buffer); @@ -136,24 +136,24 @@ buffer_measure_starts_widths_(Buffer_Measure_Starts *state, Buffer_Type *buffer, buffer_measure_starts_widths_end: state->i = i; - state->count = (int)(start_ptr - buffer->line_starts); + state->count = (i32)(start_ptr - buffer->line_starts); state->start = start; state->width = width; return(result); } -internal_4tech int +internal_4tech i32 buffer_measure_starts_zero_widths_(Buffer_Measure_Starts *state, Buffer_Type *buffer){ Buffer_Stringify_Type loop; - int *start_ptr, *start_end; - float *width_ptr; - debug_4tech(int widths_max); - debug_4tech(int max); + i32 *start_ptr, *start_end; + f32 *width_ptr; + debug_4tech(i32 widths_max); + debug_4tech(i32 max); char *data; - int size, end; - int start, i; - int result; + i32 size, end; + i32 start, i; + i32 result; char ch; size = buffer_size(buffer); @@ -197,15 +197,15 @@ buffer_measure_starts_zero_widths_(Buffer_Measure_Starts *state, Buffer_Type *bu buffer_measure_starts_zero_widths_end: state->i = i; - state->count = (int)(start_ptr - buffer->line_starts); + state->count = (i32)(start_ptr - buffer->line_starts); state->start = start; return(result); } -internal_4tech int -buffer_measure_starts_widths(Buffer_Measure_Starts *state, Buffer_Type *buffer, float *advance_data){ - int result = 0; +internal_4tech i32 +buffer_measure_starts_widths(Buffer_Measure_Starts *state, Buffer_Type *buffer, f32 *advance_data){ + i32 result = 0; if (advance_data){ result = buffer_measure_starts_widths_(state, buffer, advance_data); @@ -218,13 +218,13 @@ buffer_measure_starts_widths(Buffer_Measure_Starts *state, Buffer_Type *buffer, } internal_4tech void -buffer_remeasure_starts(Buffer_Type *buffer, int line_start, int line_end, int line_shift, int text_shift){ +buffer_remeasure_starts(Buffer_Type *buffer, i32 line_start, i32 line_end, i32 line_shift, i32 text_shift){ Buffer_Stringify_Type loop; - int *starts = buffer->line_starts; - int line_count = buffer->line_count; + i32 *starts = buffer->line_starts; + i32 line_count = buffer->line_count; char *data = 0; - int size = 0, end = 0; - int line_i = 0, char_i = 0, start = 0; + i32 size = 0, end = 0; + i32 line_i = 0, char_i = 0, start = 0; assert_4tech(0 <= line_start); assert_4tech(line_start <= line_end); @@ -243,7 +243,7 @@ buffer_remeasure_starts(Buffer_Type *buffer, int line_start, int line_end, int l if (line_shift != 0){ memmove_4tech(starts + line_end + line_shift, starts + line_end, - sizeof(int)*(line_count - line_end)); + sizeof(i32)*(line_count - line_end)); line_count += line_shift; } @@ -277,17 +277,17 @@ buffer_remeasure_starts(Buffer_Type *buffer, int line_start, int line_end, int l } internal_4tech void -buffer_remeasure_widths(Buffer_Type *buffer, float *advance_data, - int line_start, int line_end, int line_shift){ +buffer_remeasure_widths(Buffer_Type *buffer, f32 *advance_data, + i32 line_start, i32 line_end, i32 line_shift){ Buffer_Stringify_Type loop; - int *starts = buffer->line_starts; - float *widths = buffer->line_widths; - int line_count = buffer->line_count; - int widths_count = buffer->widths_count; + i32 *starts = buffer->line_starts; + f32 *widths = buffer->line_widths; + i32 line_count = buffer->line_count; + i32 widths_count = buffer->widths_count; char *data = 0; - int size = 0, end = 0; - int i = 0, j = 0; - float width = 0; + i32 size = 0, end = 0; + i32 i = 0, j = 0; + f32 width = 0; char ch = 0; assert_4tech(0 <= line_start); @@ -297,7 +297,7 @@ buffer_remeasure_widths(Buffer_Type *buffer, float *advance_data, ++line_end; if (line_shift != 0){ memmove_4tech(widths + line_end + line_shift, widths + line_end, - sizeof(float)*(widths_count - line_end)); + sizeof(f32)*(widths_count - line_end)); } buffer->widths_count = line_count; @@ -345,11 +345,11 @@ buffer_measure_widths(Buffer_Type *buffer, void *advance_data){ #endif internal_4tech void -buffer_measure_wrap_y(Buffer_Type *buffer, float *wraps, - float font_height, float max_width){ - float *widths; - float y_pos; - int i, line_count; +buffer_measure_wrap_y(Buffer_Type *buffer, f32 *wraps, + f32 font_height, f32 max_width){ + f32 *widths; + f32 y_pos; + i32 i, line_count; line_count = buffer->line_count; widths = buffer->line_widths; @@ -362,11 +362,11 @@ buffer_measure_wrap_y(Buffer_Type *buffer, float *wraps, } } -internal_4tech int -buffer_get_line_index_range(Buffer_Type *buffer, int pos, int l_bound, int u_bound){ - int *lines; - int start, end; - int i; +internal_4tech i32 +buffer_get_line_index_range(Buffer_Type *buffer, i32 pos, i32 l_bound, i32 u_bound){ + i32 *lines; + i32 start, end; + i32 i; assert_4tech(0 <= l_bound); assert_4tech(l_bound <= u_bound); @@ -393,16 +393,16 @@ buffer_get_line_index_range(Buffer_Type *buffer, int pos, int l_bound, int u_bou return(start); } -inline_4tech int -buffer_get_line_index(Buffer_Type *buffer, int pos){ - int result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); +inline_4tech i32 +buffer_get_line_index(Buffer_Type *buffer, i32 pos){ + i32 result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); return(result); } #ifndef NON_ABSTRACT_4TECH -internal_4tech int -buffer_get_line_index_from_wrapped_y(float *wraps, float y, float font_height, int l_bound, int u_bound){ - int start, end, i, result; +internal_4tech i32 +buffer_get_line_index_from_wrapped_y(f32 *wraps, f32 y, f32 font_height, i32 l_bound, i32 u_bound){ + i32 start, end, i, result; start = l_bound; end = u_bound; for (;;){ @@ -428,13 +428,13 @@ typedef struct Seek_State{ Full_Cursor prev_cursor; } Seek_State; -internal_4tech int -cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_width, - float font_height, float *advances, int size, char ch){ +internal_4tech i32 +cursor_seek_step(Seek_State *state, Buffer_Seek seek, i32 xy_seek, f32 max_width, + f32 font_height, f32 *advances, i32 size, char ch){ Full_Cursor cursor, prev_cursor; - float ch_width; - int result; - float x, px, y; + f32 ch_width; + i32 result; + f32 x, px, y; cursor = state->cursor; prev_cursor = state->prev_cursor; @@ -453,8 +453,8 @@ cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_wid default: ++cursor.character; - if (ch == '\r') ch_width = *(float*)(advances + '\\') + *(float*)(advances + 'r'); - else ch_width = *(float*)(advances + ch); + if (ch == '\r') ch_width = *(f32*)(advances + '\\') + *(f32*)(advances + 'r'); + else ch_width = *(f32*)(advances + ch); if (cursor.wrapped_x + ch_width >= max_width){ cursor.wrapped_y += font_height; @@ -536,16 +536,16 @@ cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_wid #endif internal_4tech Full_Cursor -buffer_cursor_seek(Buffer_Type *buffer, Buffer_Seek seek, float max_width, - float font_height, float *advance_data, Full_Cursor cursor){ +buffer_cursor_seek(Buffer_Type *buffer, Buffer_Seek seek, f32 max_width, + f32 font_height, f32 *advance_data, Full_Cursor cursor){ Buffer_Stringify_Type loop; char *data; - int size, end; - int i; - int result; + i32 size, end; + i32 i; + i32 result; Seek_State state; - int xy_seek; + i32 xy_seek; state.cursor = cursor; @@ -596,7 +596,7 @@ buffer_cursor_seek(Buffer_Type *buffer, Buffer_Seek seek, float max_width, } internal_4tech Partial_Cursor -buffer_partial_from_pos(Buffer_Type *buffer, int pos){ +buffer_partial_from_pos(Buffer_Type *buffer, i32 pos){ Partial_Cursor result = {0}; int32_t size = buffer_size(buffer); @@ -607,7 +607,7 @@ buffer_partial_from_pos(Buffer_Type *buffer, int pos){ pos = 0; } - int line_index = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); + i32 line_index = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); result.pos = pos; result.line = line_index+1; result.character = pos - buffer->line_starts[line_index] + 1; @@ -616,10 +616,10 @@ buffer_partial_from_pos(Buffer_Type *buffer, int pos){ } internal_4tech Full_Cursor -buffer_cursor_from_pos(Buffer_Type *buffer, int pos, float *wraps, - float max_width, float font_height, float *advance_data){ +buffer_cursor_from_pos(Buffer_Type *buffer, i32 pos, f32 *wraps, + f32 max_width, f32 font_height, f32 *advance_data){ Full_Cursor result; - int line_index; + i32 line_index; int32_t size = buffer_size(buffer); if (pos > size){ @@ -638,18 +638,18 @@ buffer_cursor_from_pos(Buffer_Type *buffer, int pos, float *wraps, } internal_4tech Partial_Cursor -buffer_partial_from_line_character(Buffer_Type *buffer, int line, int character){ +buffer_partial_from_line_character(Buffer_Type *buffer, i32 line, i32 character){ Partial_Cursor result = {0}; - int line_index = line - 1; + i32 line_index = line - 1; if (line_index >= buffer->line_count) line_index = buffer->line_count - 1; if (line_index < 0) line_index = 0; int32_t size = buffer_size(buffer); - int this_start = buffer->line_starts[line_index]; - int max_character = (size-this_start) + 1; + i32 this_start = buffer->line_starts[line_index]; + i32 max_character = (size-this_start) + 1; if (line_index+1 < buffer->line_count){ - int next_start = buffer->line_starts[line_index+1]; + i32 next_start = buffer->line_starts[line_index+1]; max_character = (next_start-this_start); } @@ -664,11 +664,11 @@ buffer_partial_from_line_character(Buffer_Type *buffer, int line, int character) } internal_4tech Full_Cursor -buffer_cursor_from_line_character(Buffer_Type *buffer, int line, int character, float *wraps, - float max_width, float font_height, float *advance_data){ +buffer_cursor_from_line_character(Buffer_Type *buffer, i32 line, i32 character, f32 *wraps, + f32 max_width, f32 font_height, f32 *advance_data){ Full_Cursor result = {0}; - int line_index = line - 1; + i32 line_index = line - 1; if (line_index >= buffer->line_count) line_index = buffer->line_count - 1; if (line_index < 0) line_index = 0; @@ -680,12 +680,12 @@ buffer_cursor_from_line_character(Buffer_Type *buffer, int line, int character, } internal_4tech Full_Cursor -buffer_cursor_from_unwrapped_xy(Buffer_Type *buffer, float x, float y, int round_down, float *wraps, - float max_width, float font_height, float *advance_data){ +buffer_cursor_from_unwrapped_xy(Buffer_Type *buffer, f32 x, f32 y, i32 round_down, f32 *wraps, + f32 max_width, f32 font_height, f32 *advance_data){ Full_Cursor result; - int line_index; + i32 line_index; - line_index = (int)(y / font_height); + line_index = (i32)(y / font_height); if (line_index >= buffer->line_count) line_index = buffer->line_count - 1; if (line_index < 0) line_index = 0; @@ -697,10 +697,10 @@ buffer_cursor_from_unwrapped_xy(Buffer_Type *buffer, float x, float y, int round } internal_4tech Full_Cursor -buffer_cursor_from_wrapped_xy(Buffer_Type *buffer, float x, float y, int round_down, float *wraps, - float max_width, float font_height, float *advance_data){ +buffer_cursor_from_wrapped_xy(Buffer_Type *buffer, f32 x, f32 y, i32 round_down, f32 *wraps, + f32 max_width, f32 font_height, f32 *advance_data){ Full_Cursor result; - int line_index; + i32 line_index; line_index = buffer_get_line_index_from_wrapped_y(wraps, y, font_height, 0, buffer->line_count); result = make_cursor_hint(line_index, buffer->line_starts, wraps, font_height); @@ -712,9 +712,9 @@ buffer_cursor_from_wrapped_xy(Buffer_Type *buffer, float x, float y, int round_d internal_4tech void buffer_invert_edit_shift(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, - int *str_pos, int max, int shift_amount){ - int pos = *str_pos; - int len = edit.end - edit.start; + i32 *str_pos, i32 max, i32 shift_amount){ + i32 pos = *str_pos; + i32 len = edit.end - edit.start; assert_4tech(pos >= 0); assert_4tech(pos + len <= max); *str_pos = pos + len; @@ -728,25 +728,25 @@ buffer_invert_edit_shift(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inv inline_4tech void buffer_invert_edit(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, - int *str_pos, int max){ + i32 *str_pos, i32 max){ buffer_invert_edit_shift(buffer, edit, inverse, strings, str_pos, max, 0); } #ifndef NON_ABSTRACT_4TECH typedef struct Buffer_Invert_Batch{ - int i; - int shift_amount; - int len; + i32 i; + i32 shift_amount; + i32 len; } Buffer_Invert_Batch; #endif -internal_4tech int -buffer_invert_batch(Buffer_Invert_Batch *state, Buffer_Type *buffer, Buffer_Edit *edits, int count, - Buffer_Edit *inverse, char *strings, int *str_pos, int max){ +internal_4tech i32 +buffer_invert_batch(Buffer_Invert_Batch *state, Buffer_Type *buffer, Buffer_Edit *edits, i32 count, + Buffer_Edit *inverse, char *strings, i32 *str_pos, i32 max){ Buffer_Edit *edit, *inv_edit; - int shift_amount; - int result; - int i; + i32 shift_amount; + i32 result; + i32 i; result = 0; i = state->i; @@ -777,8 +777,8 @@ struct Buffer_Render_Options{ }; internal_4tech Full_Cursor -buffer_get_start_cursor(Buffer_Type *buffer, float *wraps, float scroll_y, - int wrapped, float width, float *advance_data, float font_height){ +buffer_get_start_cursor(Buffer_Type *buffer, f32 *wraps, f32 scroll_y, + i32 wrapped, f32 width, f32 *advance_data, f32 font_height){ Full_Cursor result; if (wrapped){ @@ -796,19 +796,19 @@ buffer_get_start_cursor(Buffer_Type *buffer, float *wraps, float scroll_y, #define BRFlag_Special_Character (1 << 0) typedef struct Buffer_Render_Item{ - int index; + i32 index; unsigned short glyphid; unsigned short flags; - float x0, y0; - float x1, y1; + f32 x0, y0; + f32 x1, y1; } Buffer_Render_Item; inline_4tech void write_render_item(Buffer_Render_Item *item, - int index, + i32 index, unsigned short glyphid, - float x, float y, - float w, float h){ + f32 x, f32 y, + f32 w, f32 h){ item->index = index; item->glyphid = glyphid; item->x0 = x; @@ -817,36 +817,36 @@ write_render_item(Buffer_Render_Item *item, item->y1 = y + h; } -inline_4tech float +inline_4tech f32 write_render_item_inline(Buffer_Render_Item *item, - int index, + i32 index, unsigned short glyphid, - float x, float y, - float *advance_data, float h){ - float ch_width; + f32 x, f32 y, + f32 *advance_data, f32 h){ + f32 ch_width; ch_width = measure_character(advance_data, (char)glyphid); write_render_item(item, index, glyphid, x, y, ch_width, h); return(ch_width); } internal_4tech void -buffer_get_render_data(Buffer_Type *buffer, Buffer_Render_Item *items, int max, int *count, - float port_x, float port_y, - float scroll_x, float scroll_y, Full_Cursor start_cursor, - int wrapped, - float width, float height, - float *advance_data, float font_height, +buffer_get_render_data(Buffer_Type *buffer, Buffer_Render_Item *items, i32 max, i32 *count, + f32 port_x, f32 port_y, + f32 scroll_x, f32 scroll_y, Full_Cursor start_cursor, + i32 wrapped, + f32 width, f32 height, + f32 *advance_data, f32 font_height, Buffer_Render_Options opts){ Buffer_Stringify_Type loop; Buffer_Render_Item *item; Buffer_Render_Item *item_end; char *data; - int size, end; - float shift_x, shift_y; - float x, y; - int i, item_i; - float ch_width, ch_width_sub; + i32 size, end; + f32 shift_x, shift_y; + f32 x, y; + i32 i, item_i; + f32 ch_width, ch_width_sub; uint8_t ch; size = buffer_size(buffer); diff --git a/buffer/4coder_gap_buffer.cpp b/buffer/4coder_gap_buffer.cpp index 09860aea..10c847a7 100644 --- a/buffer/4coder_gap_buffer.cpp +++ b/buffer/4coder_gap_buffer.cpp @@ -1,53 +1,49 @@ -/* +/* * Mr. 4th Dimention - Allen Webster - * Four Tech * - * public domain -- no warranty is offered or implied; use this code at your own risk - * * 23.10.2015 - * - * Buffer data object - * type - Gap Buffer - * + * + * An implementation of a gap buffer. + * */ // TOP typedef struct Gap_Buffer{ char *data; - int size1; - int gap_size; - int size2; - int max; + i32 size1; + i32 gap_size; + i32 size2; + i32 max; - float *line_widths; - int *line_starts; - int line_count; - int widths_count; - int line_max; - int widths_max; + f32 *line_widths; + i32 *line_starts; + i32 line_count; + i32 widths_count; + i32 line_max; + i32 widths_max; } Gap_Buffer; -inline_4tech int +inline_4tech i32 buffer_good(Gap_Buffer *buffer){ - int good = (buffer->data != 0); + i32 good = (buffer->data != 0); return(good); } -inline_4tech int +inline_4tech i32 buffer_size(Gap_Buffer *buffer){ - int size = buffer->size1 + buffer->size2; + i32 size = buffer->size1 + buffer->size2; return(size); } typedef struct Gap_Buffer_Init{ Gap_Buffer *buffer; char *data; - int size; + i32 size; } Gap_Buffer_Init; internal_4tech Gap_Buffer_Init -buffer_begin_init(Gap_Buffer *buffer, char *data, int size){ +buffer_begin_init(Gap_Buffer *buffer, char *data, i32 size){ Gap_Buffer_Init init; init.buffer = buffer; init.data = data; @@ -55,31 +51,31 @@ buffer_begin_init(Gap_Buffer *buffer, char *data, int size){ return(init); } -internal_4tech int +internal_4tech i32 buffer_init_need_more(Gap_Buffer_Init *init){ - int result = 1; + i32 result = 1; if (init->buffer->data) result = 0; return(result); } -internal_4tech int +internal_4tech i32 buffer_init_page_size(Gap_Buffer_Init *init){ - int result = init->size * 2; + i32 result = init->size * 2; return(result); } internal_4tech void -buffer_init_provide_page(Gap_Buffer_Init *init, void *page, int page_size){ +buffer_init_provide_page(Gap_Buffer_Init *init, void *page, i32 page_size){ Gap_Buffer *buffer = init->buffer; buffer->data = (char*)page; buffer->max = page_size; } -internal_4tech int -buffer_end_init(Gap_Buffer_Init *init, void *scratch, int scratch_size){ +internal_4tech i32 +buffer_end_init(Gap_Buffer_Init *init, void *scratch, i32 scratch_size){ Gap_Buffer *buffer = init->buffer; - int osize1 = 0, size1 = 0, size2 = 0, size = init->size; - int result = 0; + i32 osize1 = 0, size1 = 0, size2 = 0, size = init->size; + i32 result = 0; if (buffer->data){ if (buffer->max >= init->size){ @@ -108,14 +104,14 @@ buffer_end_init(Gap_Buffer_Init *init, void *scratch, int scratch_size){ typedef struct Gap_Buffer_Stringify_Loop{ Gap_Buffer *buffer; char *data, *base; - int absolute_pos; - int pos, end; - int size; - int separated; + i32 absolute_pos; + i32 pos, end; + i32 size; + i32 separated; } Gap_Buffer_Stringify_Loop; internal_4tech Gap_Buffer_Stringify_Loop -buffer_stringify_loop(Gap_Buffer *buffer, int start, int end){ +buffer_stringify_loop(Gap_Buffer *buffer, i32 start, i32 end){ Gap_Buffer_Stringify_Loop result = {0}; if (0 <= start && start < end && end <= buffer->size1 + buffer->size2){ @@ -157,15 +153,15 @@ buffer_stringify_loop(Gap_Buffer *buffer, int start, int end){ return(result); } -inline_4tech int +inline_4tech i32 buffer_stringify_good(Gap_Buffer_Stringify_Loop *loop){ - int result = (loop->buffer != 0); + i32 result = (loop->buffer != 0); return(result); } internal_4tech void buffer_stringify_next(Gap_Buffer_Stringify_Loop *loop){ - int size1 = 0, temp_end = 0; + i32 size1 = 0, temp_end = 0; if (loop->separated){ loop->separated = 0; size1 = loop->buffer->size1; @@ -184,14 +180,14 @@ buffer_stringify_next(Gap_Buffer_Stringify_Loop *loop){ typedef struct Gap_Buffer_Backify_Loop{ Gap_Buffer *buffer; char *data, *base; - int pos, end; - int size; - int absolute_pos; - int separated; + i32 pos, end; + i32 size; + i32 absolute_pos; + i32 separated; } Gap_Buffer_Backify_Loop; internal_4tech Gap_Buffer_Backify_Loop -buffer_backify_loop(Gap_Buffer *buffer, int start, int end){ +buffer_backify_loop(Gap_Buffer *buffer, i32 start, i32 end){ Gap_Buffer_Backify_Loop result = {0}; ++start; @@ -235,16 +231,16 @@ buffer_backify_loop(Gap_Buffer *buffer, int start, int end){ return(result); } -inline_4tech int +inline_4tech i32 buffer_backify_good(Gap_Buffer_Backify_Loop *loop){ - int result = (loop->buffer != 0); + i32 result = (loop->buffer != 0); return(result); } internal_4tech void buffer_backify_next(Gap_Buffer_Backify_Loop *loop){ Gap_Buffer *buffer = loop->buffer; - int temp_end = 0; + i32 temp_end = 0; if (loop->separated){ loop->separated = 0; @@ -265,13 +261,13 @@ buffer_backify_next(Gap_Buffer_Backify_Loop *loop){ loop->data = loop->base + loop->pos; } -internal_4tech int -buffer_replace_range(Gap_Buffer *buffer, int start, int end, char *str, int len, int *shift_amount, - void *scratch, int scratch_memory, int *request_amount){ +internal_4tech i32 +buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len, i32 *shift_amount, + void *scratch, i32 scratch_memory, i32 *request_amount){ char *data = buffer->data; - int size = buffer_size(buffer); - int result = 0; - int move_size = 0; + i32 size = buffer_size(buffer); + i32 result = 0; + i32 move_size = 0; assert_4tech(0 <= start); assert_4tech(start <= end); @@ -309,14 +305,14 @@ buffer_replace_range(Gap_Buffer *buffer, int start, int end, char *str, int len, } // NOTE(allen): This could should be optimized for Gap_Buffer -internal_4tech int +internal_4tech i32 buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, - char *strings, int edit_count, void *scratch, int scratch_size, int *request_amount){ + char *strings, i32 edit_count, void *scratch, i32 scratch_size, i32 *request_amount){ Buffer_Edit *edit = 0; - int i = state->i; - int shift_total = state->shift_total; - int shift_amount = 0; - int result = 0; + i32 i = state->i; + i32 shift_total = state->shift_total; + i32 shift_amount = 0; + i32 result = 0; edit = sorted_edits + i; for (; i < edit_count; ++i, ++edit){ @@ -334,10 +330,10 @@ buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edi } internal_4tech void* -buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, int new_max){ +buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, i32 new_max){ void *result = buffer->data; - int size = buffer_size(buffer); - int new_gap_size = new_max - size; + i32 size = buffer_size(buffer); + i32 new_gap_size = new_max - size; assert_4tech(new_max >= size); diff --git a/buffer/4coder_shared.cpp b/buffer/4coder_shared.cpp index 50252bc5..0920f21a 100644 --- a/buffer/4coder_shared.cpp +++ b/buffer/4coder_shared.cpp @@ -1,17 +1,16 @@ -/* +/* * Mr. 4th Dimention - Allen Webster - * Four Tech * - * public domain -- no warranty is offered or implied; use this code at your own risk - * * 23.10.2015 - * + * * Items shared by gap buffer types - * + * */ // TOP +// TODO(allen): eliminate the extra defs and the extra include. + #include "../4coder_seek_types.h" #ifndef inline_4tech @@ -27,7 +26,9 @@ #endif #ifndef memzero_4tech -#define memzero_4tech(x) ((x) = {}) +#define memzero_4tech(x) do{ \ + char *p = (char*)&x; char *e = p + sizeof(x); \ + for (;p 0); buffer_quick_sort_cursors(positions, 0, count-1); } inline_4tech void -buffer_unsort_cursors(Cursor_With_Index *positions, int count){ +buffer_unsort_cursors(Cursor_With_Index *positions, i32 count){ assert_4tech(count > 0); buffer_quick_unsort_cursors(positions, 0, count-1); } internal_4tech void -buffer_update_cursors(Cursor_With_Index *sorted_positions, int count, int start, int end, int len){ - int shift_amount = (len - (end - start)); +buffer_update_cursors(Cursor_With_Index *sorted_positions, i32 count, i32 start, i32 end, i32 len){ + i32 shift_amount = (len - (end - start)); Cursor_With_Index *position = sorted_positions + count - 1; for (; position >= sorted_positions && position->pos > end; --position) position->pos += shift_amount; for (; position >= sorted_positions && position->pos >= start; --position) position->pos = start; } -internal_4tech int -buffer_batch_debug_sort_check(Buffer_Edit *sorted_edits, int edit_count){ - Buffer_Edit *edit; - int i, result, start_point; +internal_4tech i32 +buffer_batch_debug_sort_check(Buffer_Edit *sorted_edits, i32 edit_count){ + Buffer_Edit *edit = sorted_edits; + i32 i = 0, start_point = 0; + i32 result = 1; - result = 1; - start_point = 0; - - edit = sorted_edits; for (i = 0; i < edit_count; ++i, ++edit){ if (start_point > edit->start){ result = 0; break; } - start_point = (edit->end < edit->start + 1)?edit->start + 1:edit->end; + start_point = (edit->end < edit->start + 1)?(edit->start + 1):(edit->end); } return(result); } -internal_4tech int -buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, int edit_count){ +internal_4tech i32 +buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, i32 edit_count){ Buffer_Edit *edit; - int i, result; - int shift_total, shift_max; + i32 i, result; + i32 shift_total, shift_max; result = 0; shift_total = 0; @@ -208,12 +206,12 @@ buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, int edit_count){ return(shift_max); } -internal_4tech int -buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, int count, Buffer_Edit *sorted_edits, int edit_count){ +internal_4tech i32 +buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, Buffer_Edit *sorted_edits, i32 edit_count){ Cursor_With_Index *position, *end_position; Buffer_Edit *edit, *end_edit; - int start, end; - int shift_amount; + i32 start, end; + i32 shift_amount; position = sorted_positions; end_position = sorted_positions + count; @@ -249,9 +247,9 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, int count, return(shift_amount); } -internal_4tech int -eol_convert_in(char *dest, char *src, int size){ - int i, j, k; +internal_4tech i32 +eol_convert_in(char *dest, char *src, i32 size){ + i32 i, j, k; i = 0; k = 0; @@ -277,9 +275,9 @@ eol_convert_in(char *dest, char *src, int size){ return(j); } -internal_4tech int -eol_in_place_convert_in(char *data, int size){ - int i, j, k; +internal_4tech i32 +eol_in_place_convert_in(char *data, i32 size){ + i32 i, j, k; i = 0; k = 0; @@ -304,10 +302,10 @@ eol_in_place_convert_in(char *data, int size){ return(j); } -internal_4tech int -eol_convert_out(char *dest, int max, char *src, int size, int *size_out){ - int result; - int i, j; +internal_4tech i32 +eol_convert_out(char *dest, i32 max, char *src, i32 size, i32 *size_out){ + i32 result; + i32 i, j; // TODO(allen): iterative memory check? result = 1; @@ -327,10 +325,10 @@ eol_convert_out(char *dest, int max, char *src, int size, int *size_out){ return(result); } -internal_4tech int -eol_in_place_convert_out(char *data, int size, int max, int *size_out){ - int result; - int i; +internal_4tech i32 +eol_in_place_convert_out(char *data, i32 size, i32 max, i32 *size_out){ + i32 result; + i32 i; // TODO(allen): iterative memory check? result = 1; @@ -349,29 +347,29 @@ eol_in_place_convert_out(char *data, int size, int max, int *size_out){ return(result); } -inline_4tech int +inline_4tech i32 is_whitespace(char c){ - int result; + i32 result; result = (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v'); return(result); } -inline_4tech int +inline_4tech i32 is_alphanumeric_true(char c){ return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9'); } -inline_4tech int +inline_4tech i32 is_alphanumeric(char c){ return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_'); } -inline_4tech int +inline_4tech i32 is_upper(char c){ return (c >= 'A' && c <= 'Z'); } -inline_4tech int +inline_4tech i32 is_lower(char c){ return (c >= 'a' && c <= 'z'); } @@ -384,9 +382,9 @@ to_upper(char c){ return(c); } -internal_4tech int -is_match(char *a, char *b, int len){ - int result; +internal_4tech i32 +is_match(char *a, char *b, i32 len){ + i32 result; result = 1; for (;len > 0; --len, ++a, ++b) @@ -395,9 +393,9 @@ is_match(char *a, char *b, int len){ return(result); } -internal_4tech int -is_match_insensitive(char *a, char *b, int len){ - int result; +internal_4tech i32 +is_match_insensitive(char *a, char *b, i32 len){ + i32 result; result = 1; for (;len > 0; --len, ++a, ++b)