diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index 26ea1816..23991bf7 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -176,20 +176,6 @@ HOOK_SIG(my_view_adjust){ return(0); } -// NOTE(allen|a4.0.12): This is for testing it may be removed and replaced with a better test for the buffer_get_font when you eventally read this and wonder what it's about. -CUSTOM_COMMAND_SIG(write_name_of_font){ - View_Summary view = get_active_view(app, AccessOpen); - Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); - - char font_name[256]; - int32_t font_max = 256; - int32_t font_len = buffer_get_font(app, &buffer, font_name, font_max); - - if (font_len != 0){ - write_string(app, &view, &buffer, make_string(font_name, font_len)); - } -} - CUSTOM_COMMAND_SIG(newline_or_goto_position){ View_Summary view = get_active_view(app, AccessProtected); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected); @@ -538,8 +524,6 @@ default_keys(Bind_Helper *context){ bind(context, '\n', MDFR_SHIFT, newline_or_goto_position); bind(context, ' ', MDFR_SHIFT, write_character); - bind(context, ';', MDFR_ALT, write_name_of_font); - end_map(context); } diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index bdf5b1d5..2e9a8140 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -284,14 +284,13 @@ typedef struct Stream_Tokens{ } Stream_Tokens; static bool32 -init_stream_tokens(Stream_Tokens *stream, Application_Links *app, Buffer_Summary *buffer, - int32_t pos, Cpp_Token *data, int32_t count){ +init_stream_tokens(Stream_Tokens *stream, Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Token *data, int32_t count){ bool32 result = 0; refresh_buffer(app, buffer); int32_t token_count = buffer_token_count(app, buffer); - if (pos >= 0 && pos < token_count && count > 0){ + if (buffer->tokens_are_ready && pos >= 0 && pos < token_count && count > 0){ stream->app = app; stream->buffer = buffer; stream->base_tokens = data; @@ -317,7 +316,10 @@ static void end_temp_stream_token(Stream_Tokens *stream, Stream_Tokens temp){ if (stream->start != temp.start || stream->end != temp.end){ Application_Links *app = stream->app; - buffer_read_tokens(app, stream->buffer, stream->start, stream->end, stream->base_tokens); + buffer_read_tokens(app, temp.buffer, temp.start, temp.end, temp.base_tokens); + stream->tokens = stream->base_tokens - temp.start; + stream->start = temp.start; + stream->end = temp.end; } } @@ -633,6 +635,50 @@ buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, int32_t li return(result); } +static int32_t +buffer_get_line_end(Application_Links *app, Buffer_Summary *buffer, int32_t line){ + Partial_Cursor partial_cursor; + int32_t result = buffer->size; + if (line <= buffer->line_count){ + buffer_compute_cursor(app, buffer, seek_line_char(line, 65536), &partial_cursor); + result = partial_cursor.pos; + } + return(result); +} + +static bool32 +buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, int32_t line){ + Partial_Cursor start, end; + bool32 result = 0; + if (line <= buffer->line_count){ + buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &start); + buffer_compute_cursor(app, buffer, seek_line_char(line, 65536), &end); + + static const int32_t chunk_size = 1024; + char chunk[chunk_size]; + Stream_Chunk stream = {0}; + int32_t i = start.pos; + stream.max_end = end.pos; + + result = true; + if (init_stream_chunk(&stream, app, buffer, i, chunk, chunk_size)){ + bool32 still_looping = false; + do{ + for (;i < stream.end; ++i){ + char c = stream.data[i]; + if (!(c == ' ' || c == '\t' || c == '\r' || c == '\v' || c == '\n')){ + result = false; + goto double_break; + } + } + still_looping = forward_stream_chunk(&stream); + }while(still_looping); + } + double_break:; + } + return(result); +} + static int32_t buffer_get_line_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ Partial_Cursor partial_cursor; @@ -641,8 +687,7 @@ buffer_get_line_index(Application_Links *app, Buffer_Summary *buffer, int32_t po } static Cpp_Token* -get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line, - int32_t *line_start_out = 0){ +get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line, int32_t *line_start_out = 0){ int32_t line_start = buffer_get_line_start(app, buffer, line); Cpp_Get_Token_Result get_token = cpp_get_token(tokens, line_start); @@ -1697,8 +1742,7 @@ buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, int --pos; if (pos > 0){ stream.min_start = an_pos+1; - if (init_stream_chunk(&stream, app, buffer, - pos, data_chunk, sizeof(data_chunk))){ + if (init_stream_chunk(&stream, app, buffer, pos, data_chunk, sizeof(data_chunk))){ char c = 0, pc = stream.data[pos]; @@ -1985,8 +2029,6 @@ CUSTOM_COMMAND_SIG(open_long_braces_break){ long_braces(app, text, size); } -// TODO(allen): have this thing check if it is on -// a blank line and insert newlines as needed. CUSTOM_COMMAND_SIG(if0_off){ char text1[] = "\n#if 0"; int32_t size1 = sizeof(text1) - 1; @@ -2018,7 +2060,7 @@ CUSTOM_COMMAND_SIG(if0_off){ edits[1].start = range.max; edits[1].end = range.max; - buffer_batch_edit(app,&buffer, base, global_part.pos, edits, ArrayCount(edits), BatchEdit_Normal); + buffer_batch_edit(app, &buffer, base, global_part.pos, edits, ArrayCount(edits), BatchEdit_Normal); view = get_view(app, view.view_id, AccessAll); if (view.cursor.pos > view.mark.pos){ @@ -2624,9 +2666,7 @@ generic_search_all_buffers(Application_Links *app, General_Memory *general, Part Search_Range *ranges = set.ranges; String search_name = make_lit_string("*search*"); - - Buffer_Summary search_buffer = get_buffer_by_name(app, search_name.str, search_name.size, - AccessAll); + Buffer_Summary search_buffer = get_buffer_by_name(app, search_name.str, search_name.size, AccessAll); if (!search_buffer.exists){ search_buffer = create_buffer(app, search_name.str, search_name.size, BufferCreate_AlwaysNew); buffer_set_setting(app, &search_buffer, BufferSetting_Unimportant, true); @@ -2694,8 +2734,7 @@ generic_search_all_buffers(Application_Links *app, General_Memory *general, Part char *spare = push_array(part, char, str_len); if (spare == 0){ - buffer_replace_range(app, &search_buffer, - size, size, str, part_size); + buffer_replace_range(app, &search_buffer, size, size, str, part_size); size += part_size; end_temp_memory(temp); @@ -2717,6 +2756,7 @@ generic_search_all_buffers(Application_Links *app, General_Memory *general, Part append_s_char(&out_line, ' '); append_ss(&out_line, line_str); append_s_char(&out_line, '\n'); + Assert(out_line.size == str_len); end_temp_memory(line_temp); } @@ -2831,8 +2871,7 @@ CUSTOM_COMMAND_SIG(word_complete){ char space[1024]; Stream_Chunk chunk = {0}; - if (init_stream_chunk(&chunk, app, &buffer, - cursor_pos, space, sizeof(space))){ + if (init_stream_chunk(&chunk, app, &buffer, cursor_pos, space, sizeof(space))){ int32_t still_looping = true; do{ for (; cursor_pos >= chunk.start; --cursor_pos){ @@ -3691,7 +3730,7 @@ process_config_file(Application_Links *app){ end_temp_memory(temp); } else{ - print_message(app, literal("Did not find config.4coder, using default settings")); + print_message(app, literal("Did not find config.4coder, using default settings\n")); } } diff --git a/4coder_mem.h b/4coder_mem.h index 95e000c5..b04b9dc7 100644 --- a/4coder_mem.h +++ b/4coder_mem.h @@ -89,8 +89,8 @@ inline Tail_Temp_Partition begin_tail_part(Partition *data, int32_t size){ Tail_Temp_Partition result = {0}; if (data->pos + size <= data->max){ - result.handle = data; - result.old_max = data->max; + result.handle = data; + result.old_max = data->max; data->max -= size; result.part = make_part(data->base + data->max, size); } @@ -218,7 +218,7 @@ general_memory_open(General_Memory *general, void *memory, int32_t size){ insert_bubble2(&general->free_sentinel, first); } -#ifdef Assert +#if defined(Assert) static int32_t general_memory_check(General_Memory *general){ Bubble *sentinel = &general->sentinel; @@ -310,5 +310,10 @@ general_memory_reallocate_nocopy(General_Memory *general, void *old, int32_t siz 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 diff --git a/4coder_types.h b/4coder_types.h index 2597a021..fa1d5356 100644 --- a/4coder_types.h +++ b/4coder_types.h @@ -252,7 +252,7 @@ ENUM(uint32_t, Access_Flag){ only return objects that have no protection flags set.) */ AccessOpen = 0x0, /* DOC(AccessProtected is set on buffers and views that are "read only" such as - the output from an app->exec_system_command call such as *build*. This is to prevent + the output from an app->exec_system_command call into *build*. This is to prevent the user from accidentally editing output that they might prefer to keep in tact.) */ AccessProtected = 0x1, /* DOC(AccessHidden is set on any view that is not currently showing it's file, for @@ -484,8 +484,7 @@ STRUCT GUI_Scroll_Vars{ int32_t prev_target_x; }; -/* DOC(The Buffer_Seek_Type is is used in a Buffer_Seek to identify which -coordinates are suppose to be used for the seek.) +/* DOC(The Buffer_Seek_Type is is used in a Buffer_Seek to identify which coordinates are suppose to be used for the seek.) DOC_SEE(Buffer_Seek) DOC_SEE(4coder_Buffer_Positioning_System) */ @@ -542,11 +541,9 @@ STRUCT Full_Cursor{ int32_t character_pos; /* DOC(This field contains the number of the line where the cursor is located. This field is one based.) */ int32_t line; - /* DOC(This field contains the number of the character from the beginninf of the line - where the cursor is located. This field is one based.) */ + /* DOC(This field contains the number of the character from the beginninf of the line where the cursor is located. This field is one based.) */ int32_t character; - /* DOC(This field contains the number of the line where the cursor is located, taking the line wrapping - into account. This field is one based.) */ + /* DOC(This field contains the number of the line where the cursor is located, taking the line wrapping into account. This field is one based.) */ int32_t wrap_line; /* DOC(This field contains the x position measured with unwrapped lines.) */ float unwrapped_x; @@ -558,10 +555,7 @@ STRUCT Full_Cursor{ float wrapped_y; }; -/* DOC(Partial_Cursor describes the position of a cursor in all of -the coordinate systems that a invariant to the View. In other words -the coordinate systems available here can be used on a buffer that is -not currently associated with a View.) +/* DOC(Partial_Cursor describes the position of a cursor in all of the coordinate systems that a invariant to the View. In other words the coordinate systems available here can be used on a buffer that is not currently associated with a View.) DOC_SEE(4coder_Buffer_Positioning_System) */ STRUCT Partial_Cursor{ /* DOC(This field contains the cursor's position in absolute byte index positioning.) */ @@ -573,9 +567,7 @@ STRUCT Partial_Cursor{ int32_t character; }; -/* DOC(Buffer_Edit describes a range of a buffer and string to replace that range. -A Buffer_Edit has to be paired with a string that contains the actual text that -will be replaced into the buffer.) */ +/* DOC(Buffer_Edit describes a range of a buffer and string to replace that range. A Buffer_Edit has to be paired with a string that contains the actual text that will be replaced into the buffer.) */ STRUCT Buffer_Edit{ /* DOC(The str_start field specifies the first character in the accompanying string that corresponds with this edit.) */ int32_t str_start; @@ -637,15 +629,9 @@ STRUCT Buffer_Summary{ DOC_SEE(Access_Flag) DOC_SEE(Full_Cursor) */ STRUCT View_Summary{ - /* DOC( - This field indicates whether the View_Summary describes a view that is open in 4coder. - When this field is false the summary is referred to as a "null summary". - ) */ + /* DOC( This field indicates whether the View_Summary describes a view that is open in 4coder. When this field is false the summary is referred to as a "null summary". ) */ bool32 exists; - /* DOC( - If this is not a null summary, this field is the id of the associated view. - If this is a null summary then view_id is 0. - ) */ + /* DOC(If this is not a null summary, this field is the id of the associated view. If this is a null summary then view_id is 0. ) */ int32_t view_id; /* DOC(If this is not a null summary, then this is the id of the buffer this view currently sees.) */ int32_t buffer_id; @@ -660,20 +646,14 @@ STRUCT View_Summary{ float preferred_x; /* DOC(If this is not a null summary, this specifies the height of a line rendered in the view.) */ float line_height; - /* - DOC(If this is not a null summary, this indicates that the view is set to render with unwrapped lines.) - */ + /* DOC(If this is not a null summary, this indicates that the view is set to render with unwrapped lines.) */ bool32 unwrapped_lines; /* DOC(If this is not a null summary, this indicates that the view is set to highlight white space.) */ bool32 show_whitespace; - /* - DOC(If this is not a null summary, this describes the screen position in which this view's is displayed.) - */ + /* DOC(If this is not a null summary, this describes the screen position in which this view's is displayed.) */ i32_Rect view_region; - /* - DOC(If this is not a null summary, this describes the screen position in which this view's buffer is displayed. This is different from view_region, because it does not include any fixed height GUI at the top of the view.) - */ + /* DOC(If this is not a null summary, this describes the screen position in which this view's buffer is displayed. This is different from view_region, because it does not include any fixed height GUI at the top of the view.) */ i32_Rect file_region; /* DOC(If this is not a null summary, this describes the scrolling position inside the view.) */ GUI_Scroll_Vars scroll_vars; diff --git a/4cpp_lexer.h b/4cpp_lexer.h index c14abf43..67ca78ad 100644 --- a/4cpp_lexer.h +++ b/4cpp_lexer.h @@ -160,15 +160,9 @@ API_EXPORT FCPP_LINK Cpp_Get_Token_Result cpp_get_token(Cpp_Token_Array array, int32_t pos)/* DOC_PARAM(array, The array of tokens from which to get a token.) DOC_PARAM(pos, The position, measured in bytes, to get the token for.) -DOC_RETURN(A Cpp_Get_Token_Result struct is returned containing the index -of a token and a flag indicating whether the pos is contained in the token -or in whitespace after the token.) +DOC_RETURN(A Cpp_Get_Token_Result struct is returned containing the index of a token and a flag indicating whether the pos is contained in the token or in whitespace after the token.) -DOC(This call performs a binary search over all of the tokens looking -for the token that contains the specified position. If the position -is in whitespace between the tokens, the returned token index is the -index of the token immediately before the provided position. The returned -index can be -1 if the position is before the first token.) +DOC(This call finds the token that contains a particular position, or if the position is in between tokens it finds the index of the token to the left of the position. The returned index can be -1 if the position is before the first token.) DOC_SEE(Cpp_Get_Token_Result) */{ @@ -966,37 +960,17 @@ DOC_PARAM(chunk, The first or next chunk of the file being lexed.) DOC_PARAM(size, The number of bytes in the chunk including the null terminator if the chunk ends in a null terminator. If the chunk ends in a null terminator the system will interpret it as the end of the file.) DOC_PARAM(full_size, If the final chunk is not null terminated this parameter should specify the length of the file in bytes. To rely on an eventual null terminator use HAS_NULL_TERM for this parameter.) DOC_PARAM(token_array_out, The token array structure that will receive the tokens output by the lexer.) -DOC_PARAM(max_tokens_out, The maximum number of tokens to be output to the token array. To rely on the -max built into the token array pass NO_OUT_LIMIT here.) +DOC_PARAM(max_tokens_out, The maximum number of tokens to be output to the token array. To rely on the max built into the token array pass NO_OUT_LIMIT here.) + DOC(This call is the primary interface of the lexing system. It is quite general so it can be used in a lot of different ways. I will explain the general rules first, and then give some examples of common ways it might be used. -First a lexing state, Cpp_Lex_Data, must be initialized. The file to lex must be read into N contiguous chunks -of memory. An output Cpp_Token_Array must be allocated and initialized with the appropriate count and max_count -values. Then each chunk of the file must be passed to cpp_lex_step in order using the same lexing state for each call. -Every time a call to cpp_lex_step returns LexResult_NeedChunk, the next call to cpp_lex_step should use the -next chunk. If the return is some other value, the lexer hasn't finished with the current chunk and it sopped for some -other reason, so the same chunk should be used again in the next call. +First a lexing state, Cpp_Lex_Data, must be initialized. The file to lex must be read into N contiguous chunks of memory. An output Cpp_Token_Array must be allocated and initialized with the appropriate count and max_count values. Then each chunk of the file must be passed to cpp_lex_step in order using the same lexing state for each call. Every time a call to cpp_lex_step returns LexResult_NeedChunk, the next call to cpp_lex_step should use the next chunk. If the return is some other value, the lexer hasn't finished with the current chunk and it sopped for some other reason, so the same chunk should be used again in the next call. -If the file chunks contain a null terminator the lexer will return LexResult_Finished when it finds this character. -At this point calling the lexer again with the same state will result in an error. If you do not have a null -terminated chunk to end the file, you may instead pass the exact size in bytes of the entire file to the full_size -parameter and it will automatically handle the termination of the lexing state when it has read that many bytes. -If a full_size is specified and the system terminates for having seen that many bytes, it will return -LexResult_Finished. If a full_size is specified and a null character is read before the total number of bytes have -been read the system will still terminate as usual and return LexResult_Finished. +If the file chunks contain a null terminator the lexer will return LexResult_Finished when it finds this character. At this point calling the lexer again with the same state will result in an error. If you do not have a null terminated chunk to end the file, you may instead pass the exact size in bytes of the entire file to the full_size parameter and it will automatically handle the termination of the lexing state when it has read that many bytes. If a full_size is specified and the system terminates for having seen that many bytes, it will return LexResult_Finished. If a full_size is specified and a null character is read before the total number of bytes have been read the system will still terminate as usual and return LexResult_Finished. -If the system has filled the entire output array it will return LexResult_NeedTokenMemory. When this happens if you -want to continue lexing the file you can grow the token array, or switch to a new output array and then call -cpp_lex_step again with the chunk that was being lexed and the new output. You can also specify a max_tokens_out -which is limits how many new tokens will be added to the token array. Even if token_array_out still had more space -to hold tokens, if the max_tokens_out limit is hit, the lexer will stop and return LexResult_HitTokenLimit. If this -happens there is still space left in the token array, so you can resume simply by calling cpp_lex_step again with -the same chunk and the same output array. Also note that, unlike the chunks which must only be replaced when the -system says it needs a chunk. You may switch to or modify the output array in between calls as much as you like. +If the system has filled the entire output array it will return LexResult_NeedTokenMemory. When this happens if you want to continue lexing the file you can grow the token array, or switch to a new output array and then call cpp_lex_step again with the chunk that was being lexed and the new output. You can also specify a max_tokens_out which is limits how many new tokens will be added to the token array. Even if token_array_out still had more space to hold tokens, if the max_tokens_out limit is hit, the lexer will stop and return LexResult_HitTokenLimit. If this happens there is still space left in the token array, so you can resume simply by calling cpp_lex_step again with the same chunk and the same output array. Also note that, unlike the chunks which must only be replaced when the system says it needs a chunk. You may switch to or modify the output array in between calls as much as you like. -The most basic use of this system is to get it all done in one big chunk and try to allocate a nearly "infinite" output -array so that it will not run out of memory. This way you can get the entire job done in one call and then just assert -to make sure it returns LexResult_Finished to you: +The most basic use of this system is to get it all done in one big chunk and try to allocate a nearly "infinite" output array so that it will not run out of memory. This way you can get the entire job done in one call and then just assert to make sure it returns LexResult_Finished to you: CODE_EXAMPLE( Cpp_Token_Array lex_file(char *file_name){ diff --git a/4cpp_lexer_types.h b/4cpp_lexer_types.h index 8a7ca67b..f53b3b26 100644 --- a/4cpp_lexer_types.h +++ b/4cpp_lexer_types.h @@ -19,91 +19,91 @@ /* DOC(A Cpp_Token_Type classifies a token to make parsing easier. Some types are not actually output by the lexer, but exist because parsers will also make use of token types in their own output.) */ ENUM(uint32_t, Cpp_Token_Type){ - CPP_TOKEN_JUNK = 0, + CPP_TOKEN_JUNK = 0, CPP_TOKEN_COMMENT = 1, - CPP_PP_INCLUDE = 2, - CPP_PP_DEFINE = 3, - CPP_PP_UNDEF = 4, - CPP_PP_IF = 5, - CPP_PP_IFDEF = 6, - CPP_PP_IFNDEF = 7, - CPP_PP_ELSE = 8, - CPP_PP_ELIF = 9, - CPP_PP_ENDIF = 10, - CPP_PP_ERROR = 11, - CPP_PP_IMPORT = 12, - CPP_PP_USING = 13, - CPP_PP_LINE = 14, - CPP_PP_PRAGMA = 15, - CPP_PP_STRINGIFY = 16, - CPP_PP_CONCAT = 17, - CPP_PP_UNKNOWN = 18, + CPP_PP_INCLUDE = 2, + CPP_PP_DEFINE = 3, + CPP_PP_UNDEF = 4, + CPP_PP_IF = 5, + CPP_PP_IFDEF = 6, + CPP_PP_IFNDEF = 7, + CPP_PP_ELSE = 8, + CPP_PP_ELIF = 9, + CPP_PP_ENDIF = 10, + CPP_PP_ERROR = 11, + CPP_PP_IMPORT = 12, + CPP_PP_USING = 13, + CPP_PP_LINE = 14, + CPP_PP_PRAGMA = 15, + CPP_PP_STRINGIFY = 16, + CPP_PP_CONCAT = 17, + CPP_PP_UNKNOWN = 18, CPP_PP_DEFINED = 19, CPP_PP_INCLUDE_FILE = 20, CPP_PP_ERROR_MESSAGE = 21, - CPP_TOKEN_KEY_TYPE = 22, - CPP_TOKEN_KEY_MODIFIER = 23, - CPP_TOKEN_KEY_QUALIFIER = 24, + CPP_TOKEN_KEY_TYPE = 22, + CPP_TOKEN_KEY_MODIFIER = 23, + CPP_TOKEN_KEY_QUALIFIER = 24, /* DOC(This type is not stored in token output from the lexer.) */ - CPP_TOKEN_KEY_OPERATOR = 25, - CPP_TOKEN_KEY_CONTROL_FLOW = 26, + CPP_TOKEN_KEY_OPERATOR = 25, + CPP_TOKEN_KEY_CONTROL_FLOW = 26, CPP_TOKEN_KEY_CAST = 27, - CPP_TOKEN_KEY_TYPE_DECLARATION = 28, - CPP_TOKEN_KEY_ACCESS = 29, - CPP_TOKEN_KEY_LINKAGE = 30, - CPP_TOKEN_KEY_OTHER = 31, + CPP_TOKEN_KEY_TYPE_DECLARATION = 28, + CPP_TOKEN_KEY_ACCESS = 29, + CPP_TOKEN_KEY_LINKAGE = 30, + CPP_TOKEN_KEY_OTHER = 31, - CPP_TOKEN_IDENTIFIER = 32, - CPP_TOKEN_INTEGER_CONSTANT = 33, - CPP_TOKEN_CHARACTER_CONSTANT = 34, - CPP_TOKEN_FLOATING_CONSTANT = 35, - CPP_TOKEN_STRING_CONSTANT = 36, - CPP_TOKEN_BOOLEAN_CONSTANT = 37, + CPP_TOKEN_IDENTIFIER = 32, + CPP_TOKEN_INTEGER_CONSTANT = 33, + CPP_TOKEN_CHARACTER_CONSTANT = 34, + CPP_TOKEN_FLOATING_CONSTANT = 35, + CPP_TOKEN_STRING_CONSTANT = 36, + CPP_TOKEN_BOOLEAN_CONSTANT = 37, CPP_TOKEN_STATIC_ASSERT = 38, - CPP_TOKEN_BRACKET_OPEN = 39, - CPP_TOKEN_BRACKET_CLOSE = 40, - CPP_TOKEN_PARENTHESE_OPEN = 41, - CPP_TOKEN_PARENTHESE_CLOSE = 42, - CPP_TOKEN_BRACE_OPEN = 43, - CPP_TOKEN_BRACE_CLOSE = 44, + CPP_TOKEN_BRACKET_OPEN = 39, + CPP_TOKEN_BRACKET_CLOSE = 40, + CPP_TOKEN_PARENTHESE_OPEN = 41, + CPP_TOKEN_PARENTHESE_CLOSE = 42, + CPP_TOKEN_BRACE_OPEN = 43, + CPP_TOKEN_BRACE_CLOSE = 44, CPP_TOKEN_SEMICOLON = 45, CPP_TOKEN_ELLIPSIS = 46, /* DOC(This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.) */ - CPP_TOKEN_STAR = 47, + CPP_TOKEN_STAR = 47, /* DOC(This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.) */ - CPP_TOKEN_AMPERSAND = 48, + CPP_TOKEN_AMPERSAND = 48, /* DOC(This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.) */ - CPP_TOKEN_TILDE = 49, + CPP_TOKEN_TILDE = 49, /* DOC(This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.) */ - CPP_TOKEN_PLUS = 50, + CPP_TOKEN_PLUS = 50, /* DOC(This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.) */ - CPP_TOKEN_MINUS = 51, + CPP_TOKEN_MINUS = 51, /* DOC(This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.) */ - CPP_TOKEN_INCREMENT = 52, + CPP_TOKEN_INCREMENT = 52, /* DOC(This is an 'ambiguous' token type because it requires parsing to determine the full nature of the token.) */ - CPP_TOKEN_DECREMENT = 53, + CPP_TOKEN_DECREMENT = 53, // NOTE(allen): Precedence 1, LtoR - CPP_TOKEN_SCOPE = 54, + CPP_TOKEN_SCOPE = 54, // NOTE(allen): Precedence 2, LtoR /* DOC(This type is for parser use, it is not output by the lexer.) */ @@ -117,8 +117,8 @@ ENUM(uint32_t, Cpp_Token_Type){ CPP_TOKEN_CALL = 59, /* DOC(This type is for parser use, it is not output by the lexer.) */ CPP_TOKEN_INDEX = 60, - CPP_TOKEN_DOT = 61, - CPP_TOKEN_ARROW = 62, + CPP_TOKEN_DOT = 61, + CPP_TOKEN_ARROW = 62, // NOTE(allen): Precedence 3, RtoL /* DOC(This token is for parser use, it is not output by the lexer.) */ @@ -129,7 +129,7 @@ ENUM(uint32_t, Cpp_Token_Type){ CPP_TOKEN_POSITIVE = 65, /* DOC(This token is for parser use, it is not output by the lexer.) */ CPP_TOKEN_NEGAITVE = 66, - CPP_TOKEN_NOT = 67, + CPP_TOKEN_NOT = 67, /* DOC(This type is for parser use, it is not output by the lexer.) */ CPP_TOKEN_BIT_NOT = 68, @@ -156,15 +156,15 @@ ENUM(uint32_t, Cpp_Token_Type){ CPP_TOKEN_DELETE_ARRAY = 81, // NOTE(allen): Precedence 4, LtoR - CPP_TOKEN_PTRDOT = 82, - CPP_TOKEN_PTRARROW = 83, + CPP_TOKEN_PTRDOT = 82, + CPP_TOKEN_PTRARROW = 83, // NOTE(allen): Precedence 5, LtoR /* DOC(This type is for parser use, it is not output by the lexer.) */ - CPP_TOKEN_MUL = 84, - CPP_TOKEN_DIV = 85, - CPP_TOKEN_MOD = 86, + CPP_TOKEN_MUL = 84, + CPP_TOKEN_DIV = 85, + CPP_TOKEN_MOD = 86, // NOTE(allen): Precedence 6, LtoR @@ -175,14 +175,14 @@ ENUM(uint32_t, Cpp_Token_Type){ CPP_TOKEN_SUB = 88, // NOTE(allen): Precedence 7, LtoR - CPP_TOKEN_LSHIFT = 89, - CPP_TOKEN_RSHIFT = 90, + CPP_TOKEN_LSHIFT = 89, + CPP_TOKEN_RSHIFT = 90, // NOTE(allen): Precedence 8, LtoR - CPP_TOKEN_LESS = 91, - CPP_TOKEN_GRTR = 92, - CPP_TOKEN_GRTREQ = 93, - CPP_TOKEN_LESSEQ = 94, + CPP_TOKEN_LESS = 91, + CPP_TOKEN_GRTR = 92, + CPP_TOKEN_GRTREQ = 93, + CPP_TOKEN_LESSEQ = 94, // NOTE(allen): Precedence 9, LtoR CPP_TOKEN_EQEQ = 95, @@ -191,38 +191,38 @@ ENUM(uint32_t, Cpp_Token_Type){ // NOTE(allen): Precedence 10, LtoR /* DOC(This type is for parser use, it is not output by the lexer.) */ - CPP_TOKEN_BIT_AND = 97, + CPP_TOKEN_BIT_AND = 97, // NOTE(allen): Precedence 11, LtoR - CPP_TOKEN_BIT_XOR = 98, + CPP_TOKEN_BIT_XOR = 98, // NOTE(allen): Precedence 12, LtoR - CPP_TOKEN_BIT_OR = 99, + CPP_TOKEN_BIT_OR = 99, // NOTE(allen): Precedence 13, LtoR - CPP_TOKEN_AND = 100, + CPP_TOKEN_AND = 100, // NOTE(allen): Precedence 14, LtoR - CPP_TOKEN_OR = 101, + CPP_TOKEN_OR = 101, // NOTE(allen): Precedence 15, RtoL CPP_TOKEN_TERNARY_QMARK = 102, - CPP_TOKEN_COLON = 103, + CPP_TOKEN_COLON = 103, CPP_TOKEN_THROW = 104, - CPP_TOKEN_EQ = 105, - CPP_TOKEN_ADDEQ = 106, - CPP_TOKEN_SUBEQ = 107, - CPP_TOKEN_MULEQ = 108, - CPP_TOKEN_DIVEQ = 109, - CPP_TOKEN_MODEQ = 110, - CPP_TOKEN_LSHIFTEQ = 111, - CPP_TOKEN_RSHIFTEQ = 112, - CPP_TOKEN_ANDEQ = 113, - CPP_TOKEN_OREQ = 114, - CPP_TOKEN_XOREQ = 115, + CPP_TOKEN_EQ = 105, + CPP_TOKEN_ADDEQ = 106, + CPP_TOKEN_SUBEQ = 107, + CPP_TOKEN_MULEQ = 108, + CPP_TOKEN_DIVEQ = 109, + CPP_TOKEN_MODEQ = 110, + CPP_TOKEN_LSHIFTEQ = 111, + CPP_TOKEN_RSHIFTEQ = 112, + CPP_TOKEN_ANDEQ = 113, + CPP_TOKEN_OREQ = 114, + CPP_TOKEN_XOREQ = 115, // NOTE(allen): Precedence 16, LtoR - CPP_TOKEN_COMMA = 116, + CPP_TOKEN_COMMA = 116, /* DOC(This type is for parser use, it is not output by the lexer.) */ CPP_TOKEN_EOF = 117, @@ -230,16 +230,13 @@ ENUM(uint32_t, Cpp_Token_Type){ CPP_TOKEN_TYPE_COUNT = 118 }; -/* DOC(Cpp_Token represents a single lexed token. -It is the primary output of the lexing system.) +/* DOC(Cpp_Token represents a single lexed token. It is the primary output of the lexing system.) DOC_SEE(Cpp_Token_Flag) */ - STRUCT Cpp_Token{ - /* DOC(The type field indicates the type of the token. - All tokens have a type no matter the circumstances.) */ - Cpp_Token_Type type; +STRUCT Cpp_Token{ + /* DOC(The type field indicates the type of the token. All tokens have a type no matter the circumstances.) */ + Cpp_Token_Type type; - /* DOC(The start field indicates the index of the first character - of this token's lexeme.) */ + /* DOC(The start field indicates the index of the first character of this token's lexeme.) */ int32_t start; /* DOC(The size field indicates the number of bytes in this token's lexeme.) */ @@ -255,14 +252,13 @@ DOC_SEE(Cpp_Token_Flag) */ /* DOC(The Cpp_Token_Flags are used to mark up tokens with additional information.) */ ENUM(uint16_t, Cpp_Token_Flag){ /* DOC(Indicates that the token is a preprocessor directive.) */ - CPP_TFLAG_PP_DIRECTIVE = 0x1, + CPP_TFLAG_PP_DIRECTIVE = 0x1, /* DOC(Indicates that the token is on the line of a preprocessor directive.) */ - CPP_TFLAG_PP_BODY = 0x2, + CPP_TFLAG_PP_BODY = 0x2, - /* DOC(Indicates that the token spans across multiple lines. This can show up - on line comments and string literals with back slash line continuation. ) */ - CPP_TFLAG_MULTILINE = 0x4, + /* DOC(Indicates that the token spans across multiple lines. This can show up on line comments and string literals with back slash line continuation. ) */ + CPP_TFLAG_MULTILINE = 0x4, /* DOC(Indicates that the token is some kind of operator or punctuation like braces.) */ CPP_TFLAG_IS_OPERATOR = 0x8, @@ -271,19 +267,15 @@ ENUM(uint16_t, Cpp_Token_Flag){ CPP_TFLAG_IS_KEYWORD = 0x10 }; -/* DOC(Cpp_Token_Array is used to bundle together the common elements -of a growing array of Cpp_Tokens. To initialize it the tokens field should -point to a block of memory with a size equal to max_count*sizeof(Cpp_Token) -and the count should be initialized to zero.) */ - STRUCT Cpp_Token_Array{ +/* DOC(Cpp_Token_Array is used to bundle together the common elements of a growing array of Cpp_Tokens. To initialize it the tokens field should point to a block of memory with a size equal to max_count*sizeof(Cpp_Token) and the count should be initialized to zero.) */ +STRUCT Cpp_Token_Array{ /* DOC(The tokens field points to the memory used to store the array of tokens.) */ - Cpp_Token *tokens; + Cpp_Token *tokens; /* DOC(The count field counts how many tokens in the array are currently used.) */ int32_t count; - /* DOC(The max_count field specifies the maximum size the count field may grow to before - the tokens array is out of space.) */ + /* DOC(The max_count field specifies the maximum size the count field may grow to before the tokens array is out of space.) */ int32_t max_count; }; @@ -291,32 +283,26 @@ static Cpp_Token_Array null_cpp_token_array = {0}; /* DOC(Cpp_Get_Token_Result is the return result of the cpp_get_token call.) DOC_SEE(cpp_get_token) */ - STRUCT Cpp_Get_Token_Result{ - /* DOC(The token_index field indicates which token answers the query. To get the token from - the source array CODE_EXAMPLE(array.tokens[result.token_index])) */ - int32_t token_index; +STRUCT Cpp_Get_Token_Result{ + /* DOC(The token_index field indicates which token answers the query. To get the token from the source array CODE_EXAMPLE(array.tokens[result.token_index])) */ + int32_t token_index; - /* DOC(The in_whitespace field is true when the query position was actually in whitespace - after the result token.) */ - int32_t in_whitespace; + /* DOC(The in_whitespace field is true when the query position was actually in whitespace after the result token.) */ + int32_t in_whitespace; - /* DOC(If the token_index refers to an actual token, this is the start value of the token. - Otherwise this is zero.) */ + /* DOC(If the token_index refers to an actual token, this is the start value of the token. Otherwise this is zero.) */ int32_t token_start; - /* DOC(If the token_index refers to an actual token, this is the start+size value of the token. - Otherwise this is zero.) */ + /* DOC(If the token_index refers to an actual token, this is the start+size value of the token. Otherwise this is zero.) */ int32_t token_end; }; /* DOC(Cpp_Relex_Range is the return result of the cpp_get_relex_range call.) DOC_SEE(cpp_get_relex_range) */ - STRUCT Cpp_Relex_Range{ +STRUCT Cpp_Relex_Range{ /* DOC(The index of the first token in the unedited array that needs to be relexed.) */ int32_t start_token_index; - /* DOC(The index of the first token in the unedited array after the edited range - that may not need to be relexed. Sometimes a relex operation has to lex past this - position to find a token that is not effected by the edit.) */ + /* DOC(The index of the first token in the unedited array after the edited range that may not need to be relexed. Sometimes a relex operation has to lex past this position to find a token that is not effected by the edit.) */ int32_t end_token_index; }; @@ -328,14 +314,12 @@ struct Cpp_Lex_FSM{ }; static Cpp_Lex_FSM null_lex_fsm = {0}; -/* DOC(Cpp_Lex_Data represents the state of the lexer so that the system may be resumable -and the user can manage the lexer state and decide when to resume lexing with it. To create -a new lexer state call cpp_lex_data_init. +/* DOC(Cpp_Lex_Data represents the state of the lexer so that the system may be resumable and the user can manage the lexer state and decide when to resume lexing with it. To create a new lexer state call cpp_lex_data_init. The internals of the lex state should not be treated as a part of the public API.) DOC_SEE(cpp_lex_data_init) HIDE_MEMBERS() */ - STRUCT Cpp_Lex_Data{ +STRUCT Cpp_Lex_Data{ char tb[32]; int32_t tb_pos; int32_t token_start; @@ -359,23 +343,20 @@ ENUM(int32_t, Cpp_Lex_Result){ /* DOC(This indicates that the system got to the end of the file and will not accept more input.) */ LexResult_Finished = 0, - /* DOC(This indicates that the system got to the end of an input chunk and is ready to receive the - next input chunk.) */ + /* DOC(This indicates that the system got to the end of an input chunk and is ready to receive the next input chunk.) */ LexResult_NeedChunk = 1, - /* DOC(This indicates that the output array ran out of space to store tokens and needs to be - replaced or expanded before continuing.) */ + /* DOC(This indicates that the output array ran out of space to store tokens and needs to be replaced or expanded before continuing.) */ LexResult_NeedTokenMemory = 2, /* DOC(This indicates that the maximum number of output tokens as specified by the user was hit.) */ LexResult_HitTokenLimit = 3, }; -/* DOC(Cpp_Relex_Data represents the state of the relexer so that the system may be resumable. -To create a new relex state call cpp_relex_init.) +/* DOC(Cpp_Relex_Data represents the state of the relexer so that the system may be resumable. To create a new relex state call cpp_relex_init.) DOC_SEE(cpp_relex_init) HIDE_MEMBERS()*/ - STRUCT Cpp_Relex_Data{ +STRUCT Cpp_Relex_Data{ Cpp_Lex_Data lex; Cpp_Token end_token; @@ -451,7 +432,7 @@ ENUM_INTERNAL(uint8_t, Cpp_Lex_State){ }; ENUM_INTERNAL(uint8_t, Cpp_Lex_Int_State){ - LSINT_default, + LSINT_default, LSINT_u, LSINT_l, LSINT_L, diff --git a/4ed.cpp b/4ed.cpp index 31d95d9b..4abb91ac 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -272,7 +272,7 @@ panel_make_empty(System_Functions *system, App_Vars *vars, Panel *panel){ View_And_ID new_view; Assert(panel->view == 0); - new_view = live_set_alloc_view(system, &vars->live_set, panel, models); + new_view = live_set_alloc_view(&vars->live_set, panel, models); view_set_file(new_view.view, models->scratch_buffer, models); new_view.view->map = get_map(models, mapid_file); @@ -507,7 +507,7 @@ case_change_range(System_Functions *system, Mem_Options *mem, View *view, Editin system->cancel_job(BACKGROUND_THREADS, file->state.lex_job); } - file_update_history_before_edit(system, mem, file, step, 0, hist_normal); + file_update_history_before_edit(mem, file, step, 0, hist_normal); u8 *data = (u8*)file->state.buffer.data; for (i32 i = range.start; i < range.end; ++i){ @@ -516,8 +516,9 @@ case_change_range(System_Functions *system, Mem_Options *mem, View *view, Editin } } - if (file->state.token_array.tokens) + if (file->state.token_array.tokens){ file_relex_parallel(system, mem, file, range.start, range.end, 0); + } } } @@ -596,7 +597,7 @@ COMMAND_DECL(close_panel){ i32 active; if (models->layout.panel_count > 1){ - live_set_free_view(system, command->live_set, view); + live_set_free_view(command->live_set, view); panel->view = 0; div = layout_get_divider(&models->layout, panel->parent); @@ -1309,7 +1310,11 @@ app_setup_memory(System_Functions *system, Application_Memory *memory){ *vars = app_vars_zero(); 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 return(vars); } @@ -1661,7 +1666,7 @@ App_Init_Sig(app_init){ } // NOTE(allen): file setup - working_set_init(system, &models->working_set, partition, &vars->models.mem.general); + working_set_init(&models->working_set, partition, &vars->models.mem.general); models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH; models->working_set.default_minimum_base_display_width = DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH; @@ -1673,7 +1678,7 @@ App_Init_Sig(app_init){ // TODO(allen): more robust allocation solution for the clipboard if (clipboard.str){ - String *dest = working_set_next_clipboard_string(system, &models->mem.general, &models->working_set, clipboard.size); + String *dest = working_set_next_clipboard_string(&models->mem.general, &models->working_set, clipboard.size); copy_ss(dest, make_string((char*)clipboard.str, clipboard.size)); } @@ -1710,12 +1715,19 @@ App_Init_Sig(app_init){ }; for (i32 i = 0; i < ArrayCount(init_files); ++i){ - Editing_File *file = working_set_alloc_always(system, &models->working_set, general); - buffer_bind_name(system, general, &models->working_set, file, init_files[i].name); + Editing_File *file = working_set_alloc_always(&models->working_set, general); + buffer_bind_name(general, &models->working_set, file, init_files[i].name); switch (init_files[i].type){ - case 0: init_normal_file(system, models, file, 0, 0); break; - case 1: init_read_only_file(system, models, file); break; + case 0: + { + init_normal_file(system, models, file, 0, 0); + }break; + + case 1: + { + init_read_only_file(system, models, file); + }break; } file->settings.never_kill = 1; @@ -1811,8 +1823,7 @@ App_Step_Sig(app_step){ String clipboard = input->clipboard; if (clipboard.str){ - String *dest = - working_set_next_clipboard_string(system, &models->mem.general, &models->working_set, clipboard.size); + String *dest =working_set_next_clipboard_string(&models->mem.general, &models->working_set, clipboard.size); dest->size = eol_convert_in(dest->str, clipboard.str, clipboard.size); } diff --git a/4ed.h b/4ed.h index 2100d1a5..c8a92680 100644 --- a/4ed.h +++ b/4ed.h @@ -27,11 +27,12 @@ struct Application_Memory{ #define KEY_INPUT_BUFFER_DSIZE (KEY_INPUT_BUFFER_SIZE << 1) struct Key_Input_Data{ - Key_Event_Data press[KEY_INPUT_BUFFER_SIZE]; - Key_Event_Data hold[KEY_INPUT_BUFFER_SIZE]; - i32 press_count; + Key_Event_Data press[KEY_INPUT_BUFFER_SIZE]; + Key_Event_Data hold[KEY_INPUT_BUFFER_SIZE]; + i32 press_count; i32 hold_count; + // TODO(allen): determine if we still need this. char modifiers[MDFR_INDEX_COUNT]; }; static Key_Input_Data null_key_input_data = {0}; @@ -74,39 +75,39 @@ typedef struct Plat_Settings{ } Plat_Settings; #define App_Read_Command_Line_Sig(name) \ - i32 name(System_Functions *system, \ - Application_Memory *memory, \ - String current_directory, \ - Plat_Settings *plat_settings, \ - char ***files, i32 **file_count, \ - Command_Line_Parameters clparams) +i32 name(System_Functions *system, \ +Application_Memory *memory, \ +String current_directory, \ +Plat_Settings *plat_settings, \ +char ***files, i32 **file_count, \ +Command_Line_Parameters clparams) typedef App_Read_Command_Line_Sig(App_Read_Command_Line); #define App_Init_Sig(name) void \ name(System_Functions *system, \ - Render_Target *target, \ - Application_Memory *memory, \ - String clipboard, \ - String current_directory, \ - Custom_API api) +Render_Target *target, \ +Application_Memory *memory, \ +String clipboard, \ +String current_directory, \ +Custom_API api) typedef App_Init_Sig(App_Init); enum Application_Mouse_Cursor{ - APP_MOUSE_CURSOR_DEFAULT, - APP_MOUSE_CURSOR_ARROW, - APP_MOUSE_CURSOR_IBEAM, - APP_MOUSE_CURSOR_LEFTRIGHT, - APP_MOUSE_CURSOR_UPDOWN, - // never below this - APP_MOUSE_CURSOR_COUNT + APP_MOUSE_CURSOR_DEFAULT, + APP_MOUSE_CURSOR_ARROW, + APP_MOUSE_CURSOR_IBEAM, + APP_MOUSE_CURSOR_LEFTRIGHT, + APP_MOUSE_CURSOR_UPDOWN, + // never below this + APP_MOUSE_CURSOR_COUNT }; struct Application_Step_Result{ - Application_Mouse_Cursor mouse_cursor_type; + Application_Mouse_Cursor mouse_cursor_type; b32 lctrl_lalt_is_altgr; b32 trying_to_kill; b32 perform_kill; @@ -123,11 +124,11 @@ struct Application_Step_Input{ #define App_Step_Sig(name) void \ name(System_Functions *system, \ - Render_Target *target, \ - Application_Memory *memory, \ - Application_Step_Input *input, \ - Application_Step_Result *result, \ - Command_Line_Parameters params) +Render_Target *target, \ +Application_Memory *memory, \ +Application_Step_Input *input, \ +Application_Step_Result *result, \ +Command_Line_Parameters params) typedef App_Step_Sig(App_Step); diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 71a49c52..179a0974 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -248,7 +248,7 @@ DOC_SEE(Command_Line_Interface_Flag) } } else if (buffer.name){ - file = working_set_alloc_always(system, working_set, general); + file = working_set_alloc_always(working_set, general); if (file == 0){ append_ss(&feedback_str, make_lit_string("ERROR: unable to allocate a new buffer\n")); do_feedback_message(system, models, feedback_str); @@ -256,7 +256,7 @@ DOC_SEE(Command_Line_Interface_Flag) goto done; } String name = make_string_terminated(part, buffer.name, buffer.name_len); - buffer_bind_name(system, general, working_set, file, name); + buffer_bind_name(general, working_set, file, name); init_read_only_file(system, models, file); } @@ -367,7 +367,7 @@ DOC_SEE(The_4coder_Clipboard) General_Memory *general = &models->mem.general; Working_Set *working = &models->working_set; - String *dest = working_set_next_clipboard_string(system, general, working, len); + String *dest = working_set_next_clipboard_string(general, working, len); copy_ss(dest, make_string(str, len)); system->post_clipboard(*dest); } @@ -689,8 +689,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 = - file_compute_edit(system, mem, file, edits, str, str_len, inverse_edits, inv_str, inv_str_max, edit_count, type); + Edit_Spec spec = file_compute_edit(mem, file, edits, str, str_len, inverse_edits, inv_str, inv_str_max, edit_count, type); file_do_batch_edit(system, models, file, spec, hist_normal, type); @@ -714,7 +713,7 @@ DOC_RETURN(returns non-zero on success) Command_Data *cmd = (Command_Data*)app->cmd_context; Editing_File *file = imp_get_file(cmd, buffer); bool32 result = 0; - + if (file){ result = 1; switch (setting){ @@ -764,10 +763,10 @@ DOC_SEE(Buffer_Setting_ID) else{ if (value){ if (!file->settings.virtual_white){ - file_first_lex_parallel(system, &models->mem, file); + file_first_lex_parallel(system, &models->mem, file); } else{ - file_first_lex_serial(system, &models->mem, file); + file_first_lex_serial(&models->mem, file); } } } @@ -787,7 +786,7 @@ DOC_SEE(Buffer_Setting_ID) if (new_value != file->settings.display_width){ i16 font_id = file->settings.font_id; Render_Font *font = get_font_info(models->font_set, font_id)->font; - file_set_display_width_and_fix_cursor(system, models, file, new_value, (f32)font->height, font->advance_data); + file_set_display_width_and_fix_cursor(models, file, new_value, (f32)font->height, font->advance_data); } }break; @@ -800,7 +799,7 @@ DOC_SEE(Buffer_Setting_ID) if (new_value != file->settings.minimum_base_display_width){ i16 font_id = file->settings.font_id; Render_Font *font = get_font_info(models->font_set, font_id)->font; - file_set_minimum_base_display_width_and_fix_cursor(system, models, file, new_value, (f32)font->height, font->advance_data); + file_set_minimum_base_display_width_and_fix_cursor(models, file, new_value, (f32)font->height, font->advance_data); } }break; @@ -865,11 +864,11 @@ DOC_SEE(Buffer_Setting_ID) if (value){ if (!file->settings.virtual_white){ if (!file->settings.tokens_exist){ - file_first_lex_serial(system, &models->mem, file); + file_first_lex_serial(&models->mem, file); } if (!file->state.still_lexing){ - file->settings.virtual_white = 1; - full_remeasure = 1; + file->settings.virtual_white = 1; + full_remeasure = 1; } else{ result = 0; @@ -887,9 +886,9 @@ DOC_SEE(Buffer_Setting_ID) i16 font_id = file->settings.font_id; Render_Font *font = get_font_info(models->font_set, font_id)->font; - file_allocate_character_starts_as_needed(system, &models->mem.general, file); + file_allocate_character_starts_as_needed(&models->mem.general, file); buffer_measure_character_starts(&file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white); - file_measure_wraps(system, models, file, (f32)font->height, font->advance_data); + file_measure_wraps(models, file, (f32)font->height, font->advance_data); file_update_cursor_positions(models, file); } }break; @@ -954,10 +953,8 @@ Buffer_Get_Token_Index(Application_Links *app, Buffer_Summary *buffer, int32_t p DOC_PARAM(buffer, The buffer from which to get a token.) DOC_PARAM(pos, The position in the buffer in absolute coordinates.) DOC_PARAM(get_result, The output struct specifying which token contains pos.) -DOC_RETURN(Returns non-zero on success. This call can fail if the buffer doesn't exist, -or if the buffer doesn't have tokens ready.) -DOC(This call finds the token that contains a particular position, or if the position is in between -tokens it finds the index of the token to the left of the position.) +DOC_RETURN(Returns non-zero on success. This call can fail if the buffer doesn't exist, or if the buffer doesn't have tokens ready.) +DOC(This call finds the token that contains a particular position, or if the position is in between tokens it finds the index of the token to the left of the position. The returned index can be -1 if the position is before the first token.) DOC_SEE(Cpp_Get_Token_Result) DOC_SEE(cpp_get_token) */{ @@ -993,7 +990,7 @@ DOC_SEE(Buffer_Create_Flag) */{ bool32 result = 0; if (data){ - data->flags = flags; + data->flags = flags; result = 1; } return(result); @@ -1014,14 +1011,14 @@ DOC_SEE(end_buffer_creation) */{ bool32 result = 0; if (data){ - String fname = make_fixed_width_string(data->fname_space); - copy_ss(&fname, make_string(filename, filename_len)); - data->fname_len = filename_len; + String fname = make_fixed_width_string(data->fname_space); + copy_ss(&fname, make_string(filename, filename_len)); + data->fname_len = filename_len; result = 1; } return(result); } - + API_EXPORT Buffer_Summary End_Buffer_Creation(Application_Links *app, Buffer_Creation_Data *data) /* @@ -1041,14 +1038,14 @@ DOC_SEE(begin_buffer_creation) Buffer_Summary result = {0}; if (data && data->fname_len > 0){ - String fname = make_string(data->fname_space, data->fname_len); - - Editing_File *file = 0; - b32 do_new_file = 0; - Plat_Handle handle = {0}; - - Temp_Memory temp = begin_temp_memory(part); - + String fname = make_string(data->fname_space, data->fname_len); + + Editing_File *file = 0; + b32 do_new_file = 0; + Plat_Handle handle = {0}; + + Temp_Memory temp = begin_temp_memory(part); + Editing_File_Canon_Name canon = {0}; if (get_canon_name(system, &canon, fname)){ file = working_set_canon_contains(working_set, canon.name); @@ -1083,17 +1080,17 @@ DOC_SEE(begin_buffer_creation) char *buffer = push_array(part, char, size); if (buffer == 0){ - buffer = (char*)general_memory_allocate(system, general, size); + buffer = (char*)general_memory_allocate(general, size); Assert(buffer != 0); in_general_mem = 1; } if (system->load_file(handle, buffer, size)){ system->load_close(handle); - file = working_set_alloc_always(system, working_set, general); + file = working_set_alloc_always(working_set, general); if (file){ buffer_bind_file(system, general, working_set, file, canon.name); - buffer_bind_name(system, general, working_set, file, fname); + buffer_bind_name(general, working_set, file, fname); init_normal_file(system, models, file, buffer, size); fill_buffer_summary(&result, file, cmd); } @@ -1103,13 +1100,13 @@ DOC_SEE(begin_buffer_creation) } if (in_general_mem){ - general_memory_free(system, general, buffer); + general_memory_free(general, buffer); } } else if (!(flags & BufferCreate_NeverNew)){ - file = working_set_alloc_always(system, working_set, general); + file = working_set_alloc_always(working_set, general); if (file){ - buffer_bind_name(system, general, working_set, file, fname); + buffer_bind_name(general, working_set, file, fname); init_normal_file(system, models, file, 0, 0); fill_buffer_summary(&result, file, cmd); } @@ -1120,7 +1117,7 @@ DOC_SEE(begin_buffer_creation) } end_temp_memory(temp); -} + } return(result); } @@ -1142,15 +1139,15 @@ DOC_RETURN(This call returns non-zero on success.) Editing_File *file = imp_get_file(cmd, buffer); if (file){ if (file_get_sync(file) != DirtyState_UpToDate){ - result = 1; - - Partition *part = &models->mem.part; - Temp_Memory temp = begin_temp_memory(part); - String name = make_string_terminated(part, filename, filename_len); + result = 1; + + Partition *part = &models->mem.part; + Temp_Memory temp = begin_temp_memory(part); + String name = make_string_terminated(part, filename, filename_len); save_file_to_name(system, models, file, name.str); end_temp_memory(temp); } - } + } return(result); } @@ -1414,7 +1411,6 @@ in the system, the call will fail.) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; - System_Functions *system = cmd->system; Models *models = cmd->models; View *vptr = imp_get_view(cmd, view); @@ -1430,7 +1426,7 @@ in the system, the call will fail.) i32 which_child; i32 active; - live_set_free_view(system, models->live_set, vptr); + live_set_free_view(models->live_set, vptr); panel->view = 0; div = layout_get_divider(&models->layout, panel->parent); @@ -2022,7 +2018,7 @@ DOC(This call changes 4coder's default font to one of the built in fonts.) if (font_set_extract(set, font_name, &font_id)){ if (apply_to_all_files){ - global_set_font(cmd->system, cmd->models, font_id); + global_set_font(cmd->models, font_id); } else{ global_font->font_id = font_id; @@ -2039,7 +2035,6 @@ DOC_PARAM(len, The len parameter specifies the length of the name string.) DOC(This call sets the display font of a particular buffer.) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; - System_Functions *system = cmd->system; Models *models = cmd->models; Editing_File *file = imp_get_file(cmd, buffer); @@ -2049,7 +2044,7 @@ DOC(This call sets the display font of a particular buffer.) i16 font_id = 0; if (font_set_extract(set, font_name, &font_id)){ - file_set_font(system, models, file, font_id); + file_set_font(models, file, font_id); } } } @@ -2067,7 +2062,7 @@ DOC_RETURN(returns non-zero on success) Models *models = cmd->models; Editing_File *file = imp_get_file(cmd, buffer); - bool32 result = 0; + bool32 result = 0; if (file){ Font_Set *set = models->font_set; String name = make_string_cap(name_out, 0, name_max); diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index ad377423..f2ff8a56 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -25,7 +25,13 @@ #include "4ed_rendering.h" #include "4ed.h" -#include "4ed_mem.h" + +# include "4coder_mem.h" + +//#define USE_DEBUG_MEMORY +#if defined(USE_DEBUG_MEMORY) +# include "4ed_debug_mem.h" +#endif #define FCPP_FORBID_MALLOC #include "4cpp_lexer.h" diff --git a/4ed_debug_mem.h b/4ed_debug_mem.h new file mode 100644 index 00000000..5d808a3b --- /dev/null +++ b/4ed_debug_mem.h @@ -0,0 +1,78 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 01.14.2017 + * + * + * + */ + +// TOP + +#ifndef FED_DEBUG_MEM_H +#define FED_DEBUG_MEM_H + +// NOTE(allen): revent 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; + 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); +} + +static void +debug_gm_free(Debug_GM *general, void *memory){ + System_Functions *system = general->system; + system->memory_free(0, memory, 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, old_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 + diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index fe00ec06..a40b07a8 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -775,7 +775,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, if (!data){ used_general = 1; - data = (char*)general_memory_allocate(system, &mem->general, max); + data = (char*)general_memory_allocate(&mem->general, max); } } Assert(data); @@ -796,7 +796,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, file_mark_clean(file); if (used_general){ - general_memory_free(system, &mem->general, data); + general_memory_free(&mem->general, data); } end_temp_memory(temp); @@ -824,7 +824,7 @@ buffer_link_to_new_file(System_Functions *system, General_Memory *general, Worki buffer_unbind_file(system, working_set, file); } buffer_bind_file(system, general, working_set, file, canon_name.name); - buffer_bind_name(system, general, working_set, file, filename); + buffer_bind_name(general, working_set, file, filename); result = 1; } @@ -847,7 +847,7 @@ enum{ }; internal i32 -file_grow_starts_as_needed(System_Functions *system, General_Memory *general, Gap_Buffer *buffer, i32 additional_lines){ +file_grow_starts_as_needed(General_Memory *general, Gap_Buffer *buffer, i32 additional_lines){ b32 result = GROW_NOT_NEEDED; i32 max = buffer->line_max; i32 count = buffer->line_count; @@ -856,7 +856,7 @@ file_grow_starts_as_needed(System_Functions *system, General_Memory *general, Ga if (target_lines > max || max == 0){ max = l_round_up_i32(target_lines + max, Kbytes(1)); - i32 *new_lines = (i32*)general_memory_reallocate(system, general, buffer->line_starts, sizeof(i32)*count, sizeof(f32)*max); + i32 *new_lines = (i32*)general_memory_reallocate(general, buffer->line_starts, sizeof(i32)*count, sizeof(f32)*max); if (new_lines){ result = GROW_SUCCESS; @@ -894,10 +894,10 @@ file_update_cursor_positions(Models *models, Editing_File *file){ // internal void -file_measure_starts(System_Functions *system, General_Memory *general, Gap_Buffer *buffer){ +file_measure_starts(General_Memory *general, Gap_Buffer *buffer){ if (!buffer->line_starts){ i32 max = buffer->line_max = Kbytes(1); - buffer->line_starts = (i32*)general_memory_allocate(system, general, max*sizeof(i32)); + buffer->line_starts = (i32*)general_memory_allocate(general, max*sizeof(i32)); TentativeAssert(buffer->line_starts); // TODO(allen): when unable to allocate? } @@ -909,7 +909,7 @@ file_measure_starts(System_Functions *system, General_Memory *general, Gap_Buffe max = ((max + 1) << 1); { - i32 *new_lines = (i32*)general_memory_reallocate(system, general, buffer->line_starts, sizeof(i32)*count, sizeof(i32)*max); + i32 *new_lines = (i32*)general_memory_reallocate(general, buffer->line_starts, sizeof(i32)*count, sizeof(i32)*max); // TODO(allen): when unable to grow? TentativeAssert(new_lines); @@ -922,11 +922,11 @@ file_measure_starts(System_Functions *system, General_Memory *general, Gap_Buffe // NOTE(allen): These calls assumes that the buffer's line starts are already correct, // and that the buffer's line_count is correct. internal void -file_allocate_metadata_as_needed(System_Functions *system, General_Memory *general, Gap_Buffer *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){ +file_allocate_metadata_as_needed(General_Memory *general, Gap_Buffer *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){ if (*mem == 0){ i32 max = ((count+1)*2); max = (max+(0x3FF))&(~(0x3FF)); - *mem = general_memory_allocate(system, general, max*item_size); + *mem = general_memory_allocate(general, max*item_size); *mem_max_count = max; } else if (*mem_max_count < count){ @@ -934,41 +934,41 @@ file_allocate_metadata_as_needed(System_Functions *system, General_Memory *gener i32 max = ((count+1)*2); max = (max+(0x3FF))&(~(0x3FF)); - void *new_mem = general_memory_reallocate(system, general, *mem, item_size*old_max, item_size*max); + void *new_mem = general_memory_reallocate(general, *mem, item_size*old_max, item_size*max); - TentativeAssert(new_mem); + Assert(new_mem); *mem = new_mem; *mem_max_count = max; } } inline void -file_allocate_character_starts_as_needed(System_Functions *system, General_Memory *general, Editing_File *file){ - file_allocate_metadata_as_needed(system, general, &file->state.buffer, (void**)&file->state.character_starts, &file->state. character_start_max, file->state.buffer.line_count, sizeof(i32)); +file_allocate_character_starts_as_needed(General_Memory *general, Editing_File *file){ + file_allocate_metadata_as_needed(general, &file->state.buffer, (void**)&file->state.character_starts, &file->state. character_start_max, file->state.buffer.line_count, sizeof(i32)); } internal void -file_measure_character_starts(System_Functions *system, Models *models, Editing_File *file){ - file_allocate_character_starts_as_needed(system, &models->mem.general, file); +file_measure_character_starts(Models *models, Editing_File *file){ + file_allocate_character_starts_as_needed(&models->mem.general, file); buffer_measure_character_starts(&file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white); file_update_cursor_positions(models, file); } internal void -file_allocate_indents_as_needed(System_Functions *system, General_Memory *general, Editing_File *file, i32 min_last_index){ +file_allocate_indents_as_needed(General_Memory *general, Editing_File *file, i32 min_last_index){ i32 min_amount = min_last_index + 1; - file_allocate_metadata_as_needed(system, general, &file->state.buffer, (void**)&file->state.line_indents, &file->state.line_indent_max, min_amount, sizeof(f32)); + file_allocate_metadata_as_needed(general, &file->state.buffer, (void**)&file->state.line_indents, &file->state.line_indent_max, min_amount, sizeof(f32)); } inline void -file_allocate_wraps_as_needed(System_Functions *system, General_Memory *general, Editing_File *file){ - file_allocate_metadata_as_needed(system, general, &file->state.buffer, (void**)&file->state.wrap_line_index, &file->state.wrap_max, file->state.buffer.line_count, sizeof(f32)); +file_allocate_wraps_as_needed(General_Memory *general, Editing_File *file){ + file_allocate_metadata_as_needed(general, &file->state.buffer, (void**)&file->state.wrap_line_index, &file->state.wrap_max, file->state.buffer.line_count, sizeof(f32)); } inline void -file_allocate_wrap_positions_as_needed(System_Functions *system, General_Memory *general, Editing_File *file, i32 min_last_index){ +file_allocate_wrap_positions_as_needed(General_Memory *general, Editing_File *file, i32 min_last_index){ i32 min_amount = min_last_index + 1; - file_allocate_metadata_as_needed(system, general, &file->state.buffer, (void**)&file->state.wrap_positions, &file->state.wrap_position_max, min_amount, sizeof(f32)); + file_allocate_metadata_as_needed(general, &file->state.buffer, (void**)&file->state.wrap_positions, &file->state.wrap_position_max, min_amount, sizeof(f32)); } struct Code_Wrap_X{ @@ -1415,15 +1415,15 @@ get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start, b32 *adjust_ } internal void -file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, f32 font_height, f32 *adv){ +file_measure_wraps(Models *models, Editing_File *file, f32 font_height, f32 *adv){ General_Memory *general = &models->mem.general; Partition *part = &models->mem.part; Temp_Memory temp = begin_temp_memory(part); - file_allocate_wraps_as_needed(system, general, file); - file_allocate_indents_as_needed(system, general, file, file->state.buffer.line_count); - file_allocate_wrap_positions_as_needed(system, general, file, file->state.buffer.line_count); + 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); Buffer_Measure_Wrap_Params params; params.buffer = &file->state.buffer; @@ -1487,7 +1487,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, else{ do_wrap = 1; wrap_unit_end = wrap_indent_marks[stage+1].wrap_position; - file_allocate_wrap_positions_as_needed(system, general, file, wrap_position_index); + file_allocate_wrap_positions_as_needed(general, file, wrap_position_index); file->state.wrap_positions[wrap_position_index++] = stop.pos; } } @@ -1536,7 +1536,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, wrap_unit_end = i; if (x > width){ do_wrap = 1; - file_allocate_wrap_positions_as_needed(system, general, file, wrap_position_index); + file_allocate_wrap_positions_as_needed(general, file, wrap_position_index); file->state.wrap_positions[wrap_position_index++] = stop.pos; } else{ @@ -1852,7 +1852,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } if (stop.wrap_line_index >= file->state.line_indent_max){ - file_allocate_indents_as_needed(system, general, file, stop.wrap_line_index); + file_allocate_indents_as_needed(general, file, stop.wrap_line_index); } file->state.line_indents[stop.wrap_line_index] = line_shift; @@ -1863,7 +1863,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, ++file->state.wrap_line_count; - file_allocate_wrap_positions_as_needed(system, general, file, wrap_position_index); + file_allocate_wrap_positions_as_needed(general, file, wrap_position_index); file->state.wrap_positions[wrap_position_index++] = size; file->state.wrap_position_count = wrap_position_index; @@ -1871,21 +1871,21 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } internal void -file_measure_wraps_and_fix_cursor(System_Functions *system, Models *models, Editing_File *file, f32 font_height, f32 *adv){ - file_measure_wraps(system, models, file, font_height, adv); +file_measure_wraps_and_fix_cursor(Models *models, Editing_File *file, f32 font_height, f32 *adv){ + file_measure_wraps(models, file, font_height, adv); file_update_cursor_positions(models, file); } internal void -file_set_display_width_and_fix_cursor(System_Functions *system, Models *models, Editing_File *file, i32 display_width, f32 font_height, f32 *adv){ +file_set_display_width_and_fix_cursor(Models *models, Editing_File *file, i32 display_width, f32 font_height, f32 *adv){ file->settings.display_width = display_width; - file_measure_wraps_and_fix_cursor(system, models, file, font_height, adv); + file_measure_wraps_and_fix_cursor(models, file, font_height, adv); } internal void -file_set_minimum_base_display_width_and_fix_cursor(System_Functions *system, Models *models, Editing_File *file, i32 minimum_base_display_width, f32 font_height, f32 *adv){ +file_set_minimum_base_display_width_and_fix_cursor(Models *models, Editing_File *file, i32 minimum_base_display_width, f32 font_height, f32 *adv){ file->settings.minimum_base_display_width = minimum_base_display_width; - file_measure_wraps_and_fix_cursor(system, models, file, font_height, adv); + file_measure_wraps_and_fix_cursor(models, file, font_height, adv); } // @@ -1893,22 +1893,21 @@ file_set_minimum_base_display_width_and_fix_cursor(System_Functions *system, Mod // internal void -file_create_from_string(System_Functions *system, Models *models, - Editing_File *file, String val, b8 read_only = 0){ +file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, b8 read_only = 0){ Font_Set *font_set = models->font_set; General_Memory *general = &models->mem.general; Partition *part = &models->mem.part; - Gap_Buffer_Init init; + Open_File_Hook_Function *hook_open_file = models->hook_open_file; + Application_Links *app_links = &models->app_links; file->state = null_editing_file_state; - - init = buffer_begin_init(&file->state.buffer, val.str, val.size); + Gap_Buffer_Init init = buffer_begin_init(&file->state.buffer, val.str, val.size); for (; buffer_init_need_more(&init); ){ i32 page_size = buffer_init_page_size(&init); page_size = l_round_up_i32(page_size, Kbytes(4)); if (page_size < Kbytes(4)) page_size = Kbytes(4); - void *data = general_memory_allocate(system, general, page_size); + void *data = general_memory_allocate(general, page_size); buffer_init_provide_page(&init, data, page_size); } @@ -1924,48 +1923,48 @@ file_create_from_string(System_Functions *system, Models *models, // TODO(allen): batch some of these together so we can avoid // making so many passes over the buffer? - file_measure_starts(system, general, &file->state.buffer); + file_measure_starts(general, &file->state.buffer); - file_allocate_character_starts_as_needed(system, &models->mem.general, file); + file_allocate_character_starts_as_needed(general, file); buffer_measure_character_starts(&file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white); i16 font_id = models->global_font.font_id; file->settings.font_id = font_id; Render_Font *font = get_font_info(font_set, font_id)->font; - file_measure_wraps(system, models, file, (f32)font->height, font->advance_data); + file_measure_wraps(models, file, (f32)font->height, font->advance_data); file->settings.read_only = read_only; if (!read_only){ // TODO(allen): Redo undo system (if you don't mind the pun) i32 request_size = Kbytes(64); file->state.undo.undo.max = request_size; - file->state.undo.undo.strings = (u8*)general_memory_allocate(system, general, 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(system, general, request_size); + file->state.undo.undo.edits = (Edit_Step*)general_memory_allocate(general, request_size); file->state.undo.redo.max = request_size; - file->state.undo.redo.strings = (u8*)general_memory_allocate(system, general, 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(system, general, request_size); + file->state.undo.redo.edits = (Edit_Step*)general_memory_allocate(general, request_size); file->state.undo.history.max = request_size; - file->state.undo.history.strings = (u8*)general_memory_allocate(system, general, 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(system, general, request_size); + file->state.undo.history.edits = (Edit_Step*)general_memory_allocate(general, request_size); file->state.undo.children.max = request_size; - file->state.undo.children.strings = (u8*)general_memory_allocate(system, general, 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(system, general, request_size); + file->state.undo.children.edits = (Buffer_Edit*)general_memory_allocate(general, request_size); file->state.undo.history_block_count = 1; file->state.undo.history_head_block = 0; file->state.undo.current_block_normal = 1; } - if (models->hook_open_file){ - models->hook_open_file(&models->app_links, file->id.id); + if (hook_open_file){ + hook_open_file(app_links, file->id.id); } file->settings.is_initialized = 1; } @@ -1975,36 +1974,36 @@ file_close(System_Functions *system, General_Memory *general, 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(system, general, file->state.swap_array.tokens); + general_memory_free(general, file->state.swap_array.tokens); file->state.swap_array.tokens = 0; } } if (file->state.token_array.tokens){ - general_memory_free(system, general, file->state.token_array.tokens); + general_memory_free(general, file->state.token_array.tokens); } Gap_Buffer *buffer = &file->state.buffer; if (buffer->data){ - general_memory_free(system, general, buffer->data); - general_memory_free(system, general, buffer->line_starts); + general_memory_free(general, buffer->data); + general_memory_free(general, buffer->line_starts); } - general_memory_free(system, general, file->state.wrap_line_index); - general_memory_free(system, general, file->state.character_starts); - general_memory_free(system, general, file->state.line_indents); + 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); if (file->state.undo.undo.edits){ - general_memory_free(system, general, file->state.undo.undo.strings); - general_memory_free(system, general, file->state.undo.undo.edits); + general_memory_free(general, file->state.undo.undo.strings); + general_memory_free(general, file->state.undo.undo.edits); - general_memory_free(system, general, file->state.undo.redo.strings); - general_memory_free(system, general, file->state.undo.redo.edits); + general_memory_free(general, file->state.undo.redo.strings); + general_memory_free(general, file->state.undo.redo.edits); - general_memory_free(system, general, file->state.undo.history.strings); - general_memory_free(system, general, file->state.undo.history.edits); + general_memory_free(general, file->state.undo.history.strings); + general_memory_free(general, file->state.undo.history.edits); - general_memory_free(system, general, file->state.undo.children.strings); - general_memory_free(system, general, file->state.undo.children.edits); + general_memory_free(general, file->state.undo.children.strings); + general_memory_free(general, file->state.undo.children.edits); } } @@ -2085,7 +2084,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(system, general, new_max*sizeof(Cpp_Token)); + file->state.swap_array.tokens = (Cpp_Token*)general_memory_allocate(general, new_max*sizeof(Cpp_Token)); } system->release_lock(FRAME_LOCK); @@ -2100,7 +2099,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(system, general, file_token_array->tokens); + general_memory_free(general, file_token_array->tokens); } file_token_array->tokens = file->state.swap_array.tokens; file->state.swap_array.tokens = 0; @@ -2120,12 +2119,12 @@ file_kill_tokens(System_Functions *system, General_Memory *general, Editing_File if (file->state.still_lexing){ system->cancel_job(BACKGROUND_THREADS, file->state.lex_job); if (file->state.swap_array.tokens){ - general_memory_free(system, general, file->state.swap_array.tokens); + general_memory_free(general, file->state.swap_array.tokens); file->state.swap_array.tokens = 0; } } if (file->state.token_array.tokens){ - general_memory_free(system, general, file->state.token_array.tokens); + general_memory_free(general, file->state.token_array.tokens); } file->state.tokens_complete = 0; file->state.token_array = null_cpp_token_array; @@ -2151,7 +2150,7 @@ file_first_lex_parallel(System_Functions *system, Mem_Options *mem, Editing_File } internal void -file_first_lex_serial(System_Functions *system, Mem_Options *mem, Editing_File *file){ +file_first_lex_serial(Mem_Options *mem, Editing_File *file){ Partition *part = &mem->part; General_Memory *general = &mem->general; file->settings.tokens_exist = 1; @@ -2211,7 +2210,7 @@ file_first_lex_serial(System_Functions *system, Mem_Options *mem, Editing_File * { Assert(file->state.swap_array.tokens == 0); - file->state.swap_array.tokens = (Cpp_Token*) general_memory_allocate(system, general, new_max*sizeof(Cpp_Token)); + file->state.swap_array.tokens = (Cpp_Token*)general_memory_allocate(general, new_max*sizeof(Cpp_Token)); } u8 *dest = (u8*)file->state.swap_array.tokens; @@ -2224,7 +2223,7 @@ file_first_lex_serial(System_Functions *system, Mem_Options *mem, Editing_File * file_token_array->count = tokens.count; file_token_array->max_count = new_max; if (file_token_array->tokens){ - general_memory_free(system, general, file_token_array->tokens); + general_memory_free(general, file_token_array->tokens); } file_token_array->tokens = file->state.swap_array.tokens; file->state.swap_array.tokens = 0; @@ -2323,7 +2322,7 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi if (new_count > array->max_count){ i32 new_max = l_round_up_i32(new_count, Kbytes(1)); array->tokens = (Cpp_Token*) - general_memory_reallocate(system, general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token)); + general_memory_reallocate(general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token)); array->max_count = new_max; } @@ -2371,12 +2370,12 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi } internal b32 -file_relex_serial(System_Functions *system, Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){ +file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){ General_Memory *general = &mem->general; Partition *part = &mem->part; if (file->state.token_array.tokens == 0){ - file_first_lex_serial(system, mem, file); + file_first_lex_serial(mem, file); return(1); } @@ -2438,7 +2437,7 @@ file_relex_serial(System_Functions *system, Mem_Options *mem, Editing_File *file if (new_count > array->max_count){ i32 new_max = l_round_up_i32(new_count, Kbytes(1)); array->tokens = (Cpp_Token*) - general_memory_reallocate(system, general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token)); + general_memory_reallocate(general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token)); array->max_count = new_max; } @@ -2450,56 +2449,55 @@ file_relex_serial(System_Functions *system, Mem_Options *mem, Editing_File *file } internal void -undo_stack_grow_string(System_Functions *system, General_Memory *general, Edit_Stack *stack, i32 extra_size){ +undo_stack_grow_string(General_Memory *general, 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(system, general, old_str, old_max, new_max); + u8 *new_str = (u8*)general_memory_reallocate(general, old_str, old_max, new_max); stack->strings = new_str; stack->max = new_max; } internal void -undo_stack_grow_edits(System_Functions *system, General_Memory *general, Edit_Stack *stack){ +undo_stack_grow_edits(General_Memory *general, 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(system, general, old_eds, old_max*sizeof(Edit_Step), new_max*sizeof(Edit_Step)); + Edit_Step *new_eds = (Edit_Step*)general_memory_reallocate(general, old_eds, old_max*sizeof(Edit_Step), new_max*sizeof(Edit_Step)); stack->edits = new_eds; stack->edit_max = new_max; } internal void -child_stack_grow_string(System_Functions *system, General_Memory *general, Small_Edit_Stack *stack, i32 extra_size){ +child_stack_grow_string(General_Memory *general, 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(system, general, old_str, old_max, new_max); + u8 *new_str = (u8*)general_memory_reallocate(general, old_str, old_max, new_max); stack->strings = new_str; stack->max = new_max; } internal void -child_stack_grow_edits(System_Functions *system, General_Memory *general, Small_Edit_Stack *stack, i32 amount){ +child_stack_grow_edits(General_Memory *general, 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(system, general, old_eds, old_max*sizeof(Buffer_Edit), new_max*sizeof(Buffer_Edit)); + Buffer_Edit *new_eds = (Buffer_Edit*)general_memory_reallocate(general, old_eds, old_max*sizeof(Buffer_Edit), new_max*sizeof(Buffer_Edit)); stack->edits = new_eds; stack->edit_max = new_max; } internal i32 -undo_children_push(System_Functions *system, General_Memory *general, Small_Edit_Stack *children, - Buffer_Edit *edits, i32 edit_count, u8 *strings, i32 string_size){ +undo_children_push(General_Memory *general, 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(system, general, children, edit_count); + if (children->edit_count + edit_count > children->edit_max){ + child_stack_grow_edits(general, children, edit_count); + } - if (children->size + string_size > children->max) - child_stack_grow_string(system, general, children, string_size); + if (children->size + string_size > children->max){ + child_stack_grow_string(general, children, string_size); + } memcpy(children->edits + children->edit_count, edits, edit_count*sizeof(Buffer_Edit)); memcpy(children->strings + children->size, strings, string_size); @@ -2522,8 +2520,7 @@ struct Edit_Spec{ }; internal Edit_Step* -file_post_undo(System_Functions *system, General_Memory *general, Editing_File *file, - Edit_Step step, b32 do_merge, b32 can_merge){ +file_post_undo(General_Memory *general, 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; @@ -2533,12 +2530,12 @@ file_post_undo(System_Functions *system, General_Memory *general, Editing_File * Edit_Step *result = 0; if (step.child_count == 0){ - if (step.edit.end - step.edit.start + undo->size > undo->max) - undo_stack_grow_string(system, general, undo, step.edit.end - step.edit.start); + if (step.edit.end - step.edit.start + undo->size > undo->max){ + undo_stack_grow_string(general, undo, step.edit.end - step.edit.start); + } Buffer_Edit inv; - buffer_invert_edit(&file->state.buffer, step.edit, &inv, - (char*)undo->strings, &undo->size, undo->max); + buffer_invert_edit(&file->state.buffer, step.edit, &inv, (char*)undo->strings, &undo->size, undo->max); Edit_Step inv_step = {}; inv_step.edit = inv; @@ -2561,8 +2558,9 @@ file_post_undo(System_Functions *system, General_Memory *general, Editing_File * *result = inv_step; } else{ - if (undo->edit_count == undo->edit_max) - undo_stack_grow_edits(system, general, undo); + if (undo->edit_count == undo->edit_max){ + undo_stack_grow_edits(general, undo); + } result = undo->edits + (undo->edit_count++); *result = inv_step; @@ -2577,8 +2575,9 @@ file_post_undo(System_Functions *system, General_Memory *general, Editing_File * inv_step.child_count = step.inverse_child_count; inv_step.inverse_child_count = step.child_count; - if (undo->edit_count == undo->edit_max) - undo_stack_grow_edits(system, general, undo); + if (undo->edit_count == undo->edit_max){ + undo_stack_grow_edits(general, undo); + } result = undo->edits + (undo->edit_count++); *result = inv_step; } @@ -2596,23 +2595,24 @@ undo_stack_pop(Edit_Stack *stack){ } internal void -file_post_redo(System_Functions *system, General_Memory *general, Editing_File *file, Edit_Step step){ +file_post_redo(General_Memory *general, 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(system, general, redo, step.edit.end - step.edit.start); + if (step.edit.end - step.edit.start + redo->size > redo->max){ + undo_stack_grow_string(general, redo, step.edit.end - step.edit.start); + } Buffer_Edit inv; - buffer_invert_edit(&file->state.buffer, step.edit, &inv, - (char*)redo->strings, &redo->size, redo->max); + buffer_invert_edit(&file->state.buffer, step.edit, &inv, (char*)redo->strings, &redo->size, redo->max); Edit_Step inv_step = {}; inv_step.edit = inv; inv_step.type = ED_REDO; - if (redo->edit_count == redo->edit_max) - undo_stack_grow_edits(system, general, redo); + if (redo->edit_count == redo->edit_max){ + undo_stack_grow_edits(general, redo); + } redo->edits[redo->edit_count++] = inv_step; } else{ @@ -2625,7 +2625,7 @@ file_post_redo(System_Functions *system, General_Memory *general, Editing_File * inv_step.inverse_child_count = step.child_count; if (redo->edit_count == redo->edit_max){ - undo_stack_grow_edits(system, general, redo); + undo_stack_grow_edits(general, redo); } redo->edits[redo->edit_count++] = inv_step; } @@ -2654,7 +2654,7 @@ file_unpost_history_block(Editing_File *file){ } internal Edit_Step* -file_post_history(System_Functions *system, General_Memory *general, Editing_File *file, Edit_Step step, b32 do_merge, b32 can_merge){ +file_post_history(General_Memory *general, Editing_File *file, Edit_Step step, b32 do_merge, b32 can_merge){ Edit_Stack *history = &file->state.undo.history; Edit_Step *result = 0; @@ -2667,8 +2667,9 @@ file_post_history(System_Functions *system, General_Memory *general, Editing_Fil } if (step.child_count == 0){ - if (step.edit.end - step.edit.start + history->size > history->max) - undo_stack_grow_string(system, general, history, step.edit.end - step.edit.start); + if (step.edit.end - step.edit.start + history->size > history->max){ + undo_stack_grow_string(general, history, step.edit.end - step.edit.start); + } Buffer_Edit inv; buffer_invert_edit(&file->state.buffer, step.edit, &inv, @@ -2694,8 +2695,9 @@ file_post_history(System_Functions *system, General_Memory *general, Editing_Fil result = history->edits + (history->edit_count-1); } else{ - if (history->edit_count == history->edit_max) - undo_stack_grow_edits(system, general, history); + if (history->edit_count == history->edit_max){ + undo_stack_grow_edits(general, history); + } result = history->edits + (history->edit_count++); } @@ -2710,8 +2712,9 @@ file_post_history(System_Functions *system, General_Memory *general, Editing_Fil inv_step.inverse_child_count = step.child_count; inv_step.child_count = step.inverse_child_count; - if (history->edit_count == history->edit_max) - undo_stack_grow_edits(system, general, history); + if (history->edit_count == history->edit_max){ + undo_stack_grow_edits(general, history); + } result = history->edits + (history->edit_count++); *result = inv_step; } @@ -2731,61 +2734,9 @@ update_view_line_height(Models *models, View *view, i16 font_id){ view->line_height = font->height; } -internal void -view_set_file(View *view, Editing_File *file, Models *models){ - Assert(file); - - if (view->file_data.file != 0){ - touch_file(&models->working_set, view->file_data.file); - } - - File_Edit_Positions *edit_pos = view->edit_pos; - - if (edit_pos){ - edit_pos_unset(view->file_data.file, edit_pos); - edit_pos = 0; - } - - file_view_nullify_file(view); - view->file_data.file = file; - - edit_pos = edit_pos_get_new(file, view->persistent.id); - view->edit_pos = edit_pos; - - update_view_line_height(models, view, file->settings.font_id); -} - -struct Relative_Scrolling{ - f32 scroll_x, scroll_y; - f32 target_x, target_y; -}; - -internal Relative_Scrolling -view_get_relative_scrolling(View *view){ - Relative_Scrolling result = {0}; - if (view->edit_pos){ - f32 cursor_y = view_get_cursor_y(view); - result.scroll_y = cursor_y - view->edit_pos->scroll.scroll_y; - result.target_y = cursor_y - view->edit_pos->scroll.target_y; - } - return(result); -} - -internal void -view_set_relative_scrolling(View *view, Relative_Scrolling scrolling){ - f32 cursor_y = view_get_cursor_y(view); - - if (view->edit_pos){ - view->edit_pos->scroll.scroll_y = cursor_y - scrolling.scroll_y; - view->edit_pos->scroll.target_y = - ROUND32(clamp_bottom(0.f, cursor_y - scrolling.target_y)); - } -} - inline void view_cursor_move(View *view, Full_Cursor cursor){ - view_set_cursor(view, cursor, 1, - view->file_data.file->settings.unwrapped_lines); + view_set_cursor(view, cursor, 1, view->file_data.file->settings.unwrapped_lines); view->file_data.show_temp_highlight = 0; } @@ -2815,6 +2766,59 @@ view_cursor_move(View *view, i32 line, i32 character){ view_cursor_move(view, cursor); } +internal void +view_set_file(View *view, Editing_File *file, Models *models){ + Assert(file); + + if (view->file_data.file != 0){ + touch_file(&models->working_set, view->file_data.file); + } + + File_Edit_Positions *edit_pos = view->edit_pos; + + if (edit_pos){ + edit_pos_unset(view->file_data.file, edit_pos); + edit_pos = 0; + } + + file_view_nullify_file(view); + view->file_data.file = file; + + edit_pos = edit_pos_get_new(file, view->persistent.id); + view->edit_pos = edit_pos; + + update_view_line_height(models, view, file->settings.font_id); + + if (edit_pos->cursor.line == 0){ + view_cursor_move(view, 0); + } +} + +struct Relative_Scrolling{ + f32 scroll_x, scroll_y; + f32 target_x, target_y; +}; + +internal Relative_Scrolling +view_get_relative_scrolling(View *view){ + Relative_Scrolling result = {0}; + if (view->edit_pos){ + f32 cursor_y = view_get_cursor_y(view); + result.scroll_y = cursor_y - view->edit_pos->scroll.scroll_y; + result.target_y = cursor_y - view->edit_pos->scroll.target_y; + } + return(result); +} + +internal void +view_set_relative_scrolling(View *view, Relative_Scrolling scrolling){ + f32 cursor_y = view_get_cursor_y(view); + + if (view->edit_pos){ + view->edit_pos->scroll.scroll_y = cursor_y - scrolling.scroll_y; + view->edit_pos->scroll.target_y = ROUND32(clamp_bottom(0.f, cursor_y - scrolling.target_y)); + } +} inline i32_Rect view_widget_rect(View *view, i32 line_height){ @@ -2835,7 +2839,7 @@ enum History_Mode{ }; internal void -file_update_history_before_edit(System_Functions *system, Mem_Options *mem, Editing_File *file, Edit_Step step, u8 *str, History_Mode history_mode){ +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; @@ -2843,20 +2847,25 @@ file_update_history_before_edit(System_Functions *system, Mem_Options *mem, Edit switch (step.type){ case ED_NORMAL: { - if (step.edit.len == 1 && str && char_is_alpha_numeric(*str)) can_merge = 1; - if (step.edit.len == 1 && str && (can_merge || char_is_whitespace(*str))) do_merge = 1; - - if (history_mode != hist_forward){ - file_post_history(system, general, file, step, do_merge, can_merge); + if (step.edit.len == 1 && str && char_is_alpha_numeric(*str)){ + can_merge = 1; + } + if (step.edit.len == 1 && str && (can_merge || char_is_whitespace(*str))){ + do_merge = 1; } - file_post_undo(system, general, file, step, do_merge, can_merge); + if (history_mode != hist_forward){ + file_post_history(general, file, step, do_merge, can_merge); + } + + file_post_undo(general, file, step, do_merge, can_merge); }break; case ED_REVERSE_NORMAL: { - if (history_mode != hist_forward) - file_post_history(system, general, file, step, do_merge, can_merge); + if (history_mode != hist_forward){ + file_post_history(general, file, step, do_merge, can_merge); + } undo_stack_pop(&file->state.undo.undo); @@ -2896,18 +2905,17 @@ file_update_history_before_edit(System_Functions *system, Mem_Options *mem, Edit ++redo_end; if (file->state.undo.redo.edit_count + steps_of_redo > file->state.undo.redo.edit_max) - undo_stack_grow_edits(system, general, &file->state.undo.redo); + undo_stack_grow_edits(general, &file->state.undo.redo); if (file->state.undo.redo.size + strings_of_redo > file->state.undo.redo.max) - undo_stack_grow_string(system, general, &file->state.undo.redo, strings_of_redo); + undo_stack_grow_string(general, &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; i32 str_redo_pos = file->state.undo.redo.size + strings_of_redo; Edit_Step *edit_src = redo_end; - Edit_Step *edit_dest = - file->state.undo.redo.edits + file->state.undo.redo.edit_count + steps_of_redo; + Edit_Step *edit_dest = file->state.undo.redo.edits + file->state.undo.redo.edit_count + steps_of_redo; i32 undo_count = 0; for (i32 i = 0; i < steps_of_redo;){ @@ -2944,9 +2952,9 @@ file_update_history_before_edit(System_Functions *system, Mem_Options *mem, Edit case ED_UNDO: { if (history_mode != hist_forward){ - file_post_history(system, general, file, step, do_merge, can_merge); + file_post_history(general, file, step, do_merge, can_merge); } - file_post_redo(system, general, file, step); + file_post_redo(general, file, step); undo_stack_pop(&file->state.undo.undo); }break; @@ -2956,10 +2964,10 @@ file_update_history_before_edit(System_Functions *system, Mem_Options *mem, Edit if (step.edit.len == 1 && str && (can_merge || char_is_whitespace(*str))) do_merge = 1; if (history_mode != hist_forward){ - file_post_history(system, general, file, step, do_merge, can_merge); + file_post_history(general, file, step, do_merge, can_merge); } - file_post_undo(system, general, file, step, do_merge, can_merge); + file_post_undo(general, file, step, do_merge, can_merge); undo_stack_pop(&file->state.undo.redo); }break; } @@ -2991,13 +2999,11 @@ file_update_history_before_edit(System_Functions *system, Mem_Options *mem, Edit } inline void -file_pre_edit_maintenance(System_Functions *system, - General_Memory *general, - Editing_File *file){ +file_pre_edit_maintenance(System_Functions *system, General_Memory *general, 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(system, general, file->state.swap_array.tokens); + general_memory_free(general, file->state.swap_array.tokens); file->state.swap_array.tokens = 0; } file->state.still_lexing = 0; @@ -3104,7 +3110,7 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file Editing_Layout *layout = &models->layout; // NOTE(allen): fixing stuff beforewards???? - file_update_history_before_edit(system, mem, file, spec.step, spec.str, history_mode); + file_update_history_before_edit(mem, file, spec.step, spec.str, history_mode); file_pre_edit_maintenance(system, &mem->general, file); // NOTE(allen): actual text replacement @@ -3129,7 +3135,9 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file new_data = general_memory_allocate(general, request_amount); } void *old_data = buffer_edit_provide_memory(&file->state.buffer, new_data, request_amount); - if (old_data) general_memory_free(system, general, old_data); + if (old_data){ + general_memory_free(general, old_data); + } } // NOTE(allen): token fixing @@ -3138,7 +3146,7 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file file_relex_parallel(system, mem, file, start, end, shift_amount); } else{ - file_relex_serial(system, mem, file, start, end, shift_amount); + file_relex_serial(mem, file, start, end, shift_amount); } } @@ -3151,14 +3159,13 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file i32 line_shift = new_line_count - replaced_line_count; Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font; - file_grow_starts_as_needed(system, general, buffer, line_shift); + file_grow_starts_as_needed(general, buffer, line_shift); buffer_remeasure_starts(buffer, line_start, line_end, line_shift, shift_amount); - file_allocate_character_starts_as_needed(system, general, file); - buffer_remeasure_character_starts(buffer, line_start, line_end, line_shift, - file->state.character_starts, 0, file->settings.virtual_white); + file_allocate_character_starts_as_needed(general, file); + buffer_remeasure_character_starts(buffer, line_start, line_end, line_shift, file->state.character_starts, 0, file->settings.virtual_white); - // TODO(allen): Redo this as some sort of dialectic API + // TODO(allen): Redo this as some sort of dialogical API #if 0 file_allocate_wraps_as_needed(general, file); buffer_remeasure_wrap_y(buffer, line_start, line_end, line_shift, @@ -3166,7 +3173,7 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file (f32)file->settings.display_width); #endif - file_measure_wraps(system, models, file, (f32)font->height, font->advance_data); + file_measure_wraps(models, file, (f32)font->height, font->advance_data); // NOTE(allen): cursor fixing Cursor_Fix_Descriptor desc = {}; @@ -3188,7 +3195,7 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, // NOTE(allen): fixing stuff "beforewards"??? Assert(spec.str == 0); - file_update_history_before_edit(system, mem, file, spec.step, 0, history_mode); + file_update_history_before_edit(mem, file, spec.step, 0, history_mode); file_pre_edit_maintenance(system, &mem->general, file); // NOTE(allen): actual text replacement @@ -3207,11 +3214,11 @@ file_do_batch_edit(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(system, general, request_amount); + new_data = general_memory_allocate(general, request_amount); } void *old_data = buffer_edit_provide_memory(&file->state.buffer, new_data, request_amount); if (old_data){ - general_memory_free(system, general, old_data); + general_memory_free(general, old_data); } } @@ -3230,7 +3237,7 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, file_relex_parallel(system, mem, file, first_edit->start, last_edit->end, shift_total); } else{ - file_relex_serial(system, mem, file, first_edit->start, last_edit->end, shift_total); + file_relex_serial(mem, file, first_edit->start, last_edit->end, shift_total); } } }break; @@ -3277,11 +3284,11 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, buffer_measure_starts(&measure_state, &file->state.buffer); // TODO(allen): write the remeasurement version - file_allocate_character_starts_as_needed(system, &models->mem.general, file); + file_allocate_character_starts_as_needed(&models->mem.general, file); buffer_measure_character_starts(&file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white); Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font; - file_measure_wraps(system, models, file, (f32)font->height, font->advance_data); + file_measure_wraps(models, file, (f32)font->height, font->advance_data); // NOTE(allen): cursor fixing { @@ -3495,7 +3502,7 @@ view_history_step(System_Functions *system, Models *models, View *view, History_ } internal String* -working_set_next_clipboard_string(System_Functions *system, General_Memory *general, Working_Set *working, i32 str_size){ +working_set_next_clipboard_string(General_Memory *general, Working_Set *working, i32 str_size){ String *result = 0; i32 clipboard_current = working->clipboard_current; if (working->clipboard_size == 0){ @@ -3516,10 +3523,10 @@ working_set_next_clipboard_string(System_Functions *system, General_Memory *gene working->clipboard_rolling = clipboard_current; char *new_str; if (result->str){ - new_str = (char*)general_memory_reallocate(system, general, result->str, result->size, str_size); + new_str = (char*)general_memory_reallocate(general, result->str, result->size, str_size); } else{ - new_str = (char*)general_memory_allocate(system, general, str_size+1); + new_str = (char*)general_memory_allocate(general, str_size+1); } // TODO(allen): What if new_str == 0? *result = make_string_cap(new_str, 0, str_size); @@ -3565,17 +3572,14 @@ working_set_clipboard_roll_down(Working_Set *working){ internal void clipboard_copy(System_Functions *system, General_Memory *general, Working_Set *working, Range range, Editing_File *file){ i32 size = range.end - range.start; - String *dest = working_set_next_clipboard_string(system, general, working, size); + String *dest = working_set_next_clipboard_string(general, working, size); buffer_stringify(&file->state.buffer, range.start, range.end, dest->str); dest->size = size; system->post_clipboard(*dest); } internal Edit_Spec -file_compute_edit(System_Functions *system, Mem_Options *mem, 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){ +file_compute_edit(Mem_Options *mem, 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){ General_Memory *general = &mem->general; i32 inv_str_pos = 0; @@ -3585,12 +3589,8 @@ file_compute_edit(System_Functions *system, Mem_Options *mem, Editing_File *file Assert(0); } - i32 first_child = - undo_children_push(system, general, &file->state.undo.children, - edits, edit_count, (u8*)(str_base), str_size); - i32 inverse_first_child = - undo_children_push(system, general, &file->state.undo.children, - inverse_array, edit_count, (u8*)(inv_str), inv_str_pos); + 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); Edit_Spec spec = {}; spec.step.type = ED_NORMAL; @@ -3652,10 +3652,10 @@ style_get_color(Style *style, Cpp_Token token){ } internal void -file_set_font(System_Functions *system, Models *models, Editing_File *file, i16 font_id){ +file_set_font(Models *models, Editing_File *file, i16 font_id){ file->settings.font_id = font_id; Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font; - file_measure_wraps_and_fix_cursor(system, models, file, (f32)font->height, font->advance_data); + file_measure_wraps_and_fix_cursor(models, file, (f32)font->height, font->advance_data); Editing_Layout *layout = &models->layout; for (View_Iter iter = file_view_iter_init(layout, file, 0); @@ -3666,12 +3666,12 @@ file_set_font(System_Functions *system, Models *models, Editing_File *file, i16 } internal void -global_set_font(System_Functions *system, Models *models, i16 font_id){ +global_set_font(Models *models, i16 font_id){ File_Node *node = 0; File_Node *sentinel = &models->working_set.used_sentinel; for (dll_items(node, sentinel)){ Editing_File *file = (Editing_File*)node; - file_set_font(system, models, file, font_id); + file_set_font(models, file, font_id); } models->global_font.font_id = font_id; @@ -3752,7 +3752,7 @@ init_normal_file(System_Functions *system, Models *models, Editing_File *file, c file_first_lex_parallel(system, mem, file); } else{ - file_first_lex_serial(system, mem, file); + file_first_lex_serial(mem, file); } } } @@ -3768,7 +3768,7 @@ init_read_only_file(System_Functions *system, Models *models, Editing_File *file file_first_lex_parallel(system, mem, file); } else{ - file_first_lex_serial(system, mem, file); + file_first_lex_serial(mem, file); } } } @@ -3791,10 +3791,10 @@ view_open_file(System_Functions *system, Models *models, View *view, String file Mem_Options *mem = &models->mem; General_Memory *general = &mem->general; - file = working_set_alloc_always(system, working_set, general); + file = working_set_alloc_always(working_set, general); buffer_bind_file(system, general, working_set, file, canon_name.name); - buffer_bind_name(system, general, working_set, file, filename); + buffer_bind_name(general, working_set, file, filename); i32 size = system->load_size(handle); Partition *part = &mem->part; @@ -3805,7 +3805,7 @@ view_open_file(System_Functions *system, Models *models, View *view, String file buffer = push_array(part, char, size); if (buffer == 0){ - buffer = (char*)general_memory_allocate(system, general, size); + buffer = (char*)general_memory_allocate(general, size); Assert(buffer); gen_buffer = 1; } @@ -3819,7 +3819,7 @@ view_open_file(System_Functions *system, Models *models, View *view, String file } if (gen_buffer){ - general_memory_free(system, general, buffer); + general_memory_free(general, buffer); } end_temp_memory(temp); @@ -3859,10 +3859,10 @@ view_interactive_new_file(System_Functions *system, Models *models, View *view, Mem_Options *mem = &models->mem; General_Memory *general = &mem->general; - file = working_set_alloc_always(system, working_set, general); + file = working_set_alloc_always(working_set, general); buffer_bind_file(system, general, working_set, file, canon_name.name); - buffer_bind_name(system, general, working_set, file, filename); + buffer_bind_name(general, working_set, file, filename); init_normal_file(system, models, file, 0, 0); } @@ -4806,10 +4806,10 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su if (font_id != new_font_id){ if (view->color_mode == CV_Mode_Font){ - file_set_font(system, models, view->file_data.file, new_font_id); + file_set_font(models, view->file_data.file, new_font_id); } else{ - global_set_font(system, models, new_font_id); + global_set_font(models, new_font_id); } } }break; @@ -5379,7 +5379,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su } Partition *part = &models->mem.part; - General_Memory *general = &models->mem.general; string.size = 0; append_ss(&string, make_lit_string("part memory: ")); @@ -5388,8 +5387,9 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su append_int_to_str(&string, part->max); gui_do_text_field(target, string, empty_str); - Bubble *bubble, *sentinel; - sentinel = &general->sentinel; +#if !defined(FED_DEBUG_MEM_H) + General_Memory *general = &models->mem.general; + Bubble *bubble = 0, *sentinel = &general->sentinel; for (dll_items(bubble, sentinel)){ string.size = 0; if (bubble->flags & MEM_BUBBLE_USED){ @@ -5403,6 +5403,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su append_padding(&string, ' ', 40); gui_do_text_field(target, string, empty_str); } +#endif }break; case DBG_View_Inspection: @@ -6650,14 +6651,14 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol } inline void -file_view_free_buffers(System_Functions *system, View *view){ +file_view_free_buffers(View *view){ General_Memory *general = &view->persistent.models->mem.general; - general_memory_free(system, general, view->gui_mem); + general_memory_free(general, view->gui_mem); view->gui_mem = 0; } internal View_And_ID -live_set_alloc_view(System_Functions *system, Live_Views *live_set, Panel *panel, Models *models){ +live_set_alloc_view(Live_Views *live_set, Panel *panel, Models *models){ View_And_ID result = {}; Assert(live_set->count < live_set->max); @@ -6680,7 +6681,7 @@ live_set_alloc_view(System_Functions *system, Live_Views *live_set, Panel *panel { i32 gui_mem_size = Kbytes(512); - void *gui_mem = general_memory_allocate(system, &models->mem.general, gui_mem_size + 8); + void *gui_mem = general_memory_allocate(&models->mem.general, gui_mem_size + 8); result.view->gui_mem = gui_mem; gui_mem = advance_to_alignment(gui_mem); result.view->gui_target.push = make_part(gui_mem, gui_mem_size); @@ -6690,10 +6691,10 @@ live_set_alloc_view(System_Functions *system, Live_Views *live_set, Panel *panel } inline void -live_set_free_view(System_Functions *system, Live_Views *live_set, View *view){ +live_set_free_view(Live_Views *live_set, View *view){ Assert(live_set->count > 0); --live_set->count; - file_view_free_buffers(system, view); + file_view_free_buffers(view); dll_insert(&live_set->free_sentinel, view); view->in_use = 0; } diff --git a/4ed_font_set.cpp b/4ed_font_set.cpp index b2e11c80..9c4a47f3 100644 --- a/4ed_font_set.cpp +++ b/4ed_font_set.cpp @@ -174,8 +174,7 @@ font_set_use(Partition *partition, Font_Set *set, i16 font_id){ } internal b32 -font_set_add(Partition *partition, Font_Set *set, - String filename, String name, i32 pt_size){ +font_set_add(Partition *partition, Font_Set *set, String filename, String name, i32 pt_size){ b32 result = 0; if (font_set_can_add(set)){ Render_Font dummy_font = {0}; @@ -184,10 +183,7 @@ font_set_add(Partition *partition, Font_Set *set, info->filename = filename; info->name = name; info->pt_size = pt_size; - set->font_load(&dummy_font, - info->filename.str, - info->name.str, - info->pt_size, 4, false); + set->font_load(&dummy_font, info->filename.str, info->name.str, info->pt_size, 4, false); info->height = dummy_font.height; info->advance = dummy_font.advance; diff --git a/4ed_mem.h b/4ed_mem.h deleted file mode 100644 index ec01da91..00000000 --- a/4ed_mem.h +++ /dev/null @@ -1,107 +0,0 @@ - -#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, 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); -#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, old, old_size, 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, old, 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 - diff --git a/4ed_rendering_helper.cpp b/4ed_rendering_helper.cpp index da27cf7f..9c30d292 100644 --- a/4ed_rendering_helper.cpp +++ b/4ed_rendering_helper.cpp @@ -33,7 +33,7 @@ begin_render_section(Render_Target *target, System_Functions *system){ memset(font_set->font_used_flags, 0, font_set->max); target->size = 0; target->clip_top = -1; - + i32_Rect clip; clip.x0 = 0; clip.y0 = 0; @@ -112,12 +112,11 @@ draw_margin(Render_Target *target, i32_Rect outer, i32 width, u32 color){ inline internal i32 font_predict_size(i32 pt_size){ - return pt_size*pt_size*128; + return pt_size*pt_size*128; } internal void -font_draw_glyph_mono(Render_Target *target, i16 font_id, - u8 character, f32 x, f32 y, f32 advance, u32 color){ +font_draw_glyph_mono(Render_Target *target, i16 font_id, u8 character, f32 x, f32 y, f32 advance, u32 color){ Render_Piece_Combined piece; piece.header.type = piece_type_mono_glyph; piece.glyph.pos.x = x; @@ -137,8 +136,7 @@ font_draw_glyph_mono(Render_Target *target, i16 font_id, } internal void -font_draw_glyph(Render_Target *target, i16 font_id, - u8 character, f32 x, f32 y, u32 color){ +font_draw_glyph(Render_Target *target, i16 font_id, u8 character, f32 x, f32 y, u32 color){ Render_Piece_Combined piece; piece.header.type = piece_type_glyph; piece.glyph.pos.x = x; diff --git a/4ed_site.ctm b/4ed_site.ctm index f13ce96e..0d02ed61 100644 Binary files a/4ed_site.ctm and b/4ed_site.ctm differ diff --git a/system_shared.cpp b/4ed_system_shared.cpp similarity index 94% rename from system_shared.cpp rename to 4ed_system_shared.cpp index d6d25ea1..78352eef 100644 --- a/system_shared.cpp +++ b/4ed_system_shared.cpp @@ -134,12 +134,12 @@ sysshared_load_file(char *filename){ result.data = (char*)system_get_memory(size+1); if (!result.data){ - result = file_data_zero(); + result = null_file_data; } else{ if (!system_load_file(handle, result.data, size)){ system_free_memory(result.data); - result = file_data_zero(); + result = null_file_data; } } } @@ -366,8 +366,7 @@ private_draw_rectangle_outline(Render_Target *target, f32_Rect rect, u32 color){ } inline void -private_draw_gradient(Render_Target *target, f32_Rect rect, - Vec4 color_left, Vec4 color_right){ +private_draw_gradient(Render_Target *target, f32_Rect rect, Vec4 color_left, Vec4 color_right){ Vec4 cl = color_left; Vec4 cr = color_right; @@ -429,12 +428,8 @@ get_exact_render_quad(Glyph_Data *b, i32 pw, i32 ph, float xpos, float ypos){ } inline void -private_draw_glyph(Render_Target *target, Render_Font *font, - u8 character, f32 x, f32 y, u32 color){ - Render_Quad q = get_render_quad( - font->glyphs + character, - font->tex_width, font->tex_height, x, y - ); +private_draw_glyph(Render_Target *target, Render_Font *font, u8 character, f32 x, f32 y, u32 color){ + Render_Quad q = get_render_quad(font->glyphs + character, font->tex_width, font->tex_height, x, y); draw_set_color(target, color); draw_bind_texture(target, font->tex); @@ -494,59 +489,50 @@ launch_rendering(Render_Target *target){ switch (type){ case piece_type_rectangle: { - Render_Piece_Rectangle *rectangle = - ExtractStruct(Render_Piece_Rectangle); + Render_Piece_Rectangle *rectangle = ExtractStruct(Render_Piece_Rectangle); private_draw_rectangle(target, rectangle->rect, rectangle->color); }break; case piece_type_outline: { - Render_Piece_Rectangle *rectangle = - ExtractStruct(Render_Piece_Rectangle); + Render_Piece_Rectangle *rectangle = ExtractStruct(Render_Piece_Rectangle); private_draw_rectangle_outline(target, rectangle->rect, rectangle->color); }break; case piece_type_gradient: { - Render_Piece_Gradient *gradient = - ExtractStruct(Render_Piece_Gradient); - private_draw_gradient(target, gradient->rect, - unpack_color4(gradient->left_color), - unpack_color4(gradient->right_color)); + Render_Piece_Gradient *gradient = ExtractStruct(Render_Piece_Gradient); + private_draw_gradient(target, gradient->rect, unpack_color4(gradient->left_color), unpack_color4(gradient->right_color)); }break; case piece_type_glyph: { - Render_Piece_Glyph *glyph = - ExtractStruct(Render_Piece_Glyph); + Render_Piece_Glyph *glyph = ExtractStruct(Render_Piece_Glyph); Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font; - if (font) - private_draw_glyph(target, font, glyph->character, - glyph->pos.x, glyph->pos.y, glyph->color); + if (font){ + private_draw_glyph(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->color); + } }break; case piece_type_mono_glyph: { - Render_Piece_Glyph *glyph = - ExtractStruct(Render_Piece_Glyph); + Render_Piece_Glyph *glyph = ExtractStruct(Render_Piece_Glyph); Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font; - if (font) - private_draw_glyph_mono(target, font, glyph->character, - glyph->pos.x, glyph->pos.y, glyph->color); + if (font){ + private_draw_glyph_mono(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->color); + } }break; case piece_type_mono_glyph_advance: { - Render_Piece_Glyph_Advance *glyph = - ExtractStruct(Render_Piece_Glyph_Advance); + Render_Piece_Glyph_Advance *glyph = ExtractStruct(Render_Piece_Glyph_Advance); Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font; - if (font) - private_draw_glyph_mono(target, font, glyph->character, - glyph->pos.x, glyph->pos.y, - glyph->advance, glyph->color); + if (font){ + private_draw_glyph_mono(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->advance, glyph->color); + } }break; case piece_type_change_clip: diff --git a/system_shared.h b/4ed_system_shared.h similarity index 91% rename from system_shared.h rename to 4ed_system_shared.h index d0f19146..ae8bd992 100644 --- a/system_shared.h +++ b/4ed_system_shared.h @@ -19,11 +19,7 @@ struct File_Data{ u32 size; b32 got_file; }; -inline File_Data -file_data_zero(){ - File_Data result = {0}; - return(result); -} +globalvar File_Data null_file_data = {0}; #define Sys_Get_Memory_Sig(name) void* name(i32 size, i32 line_number, char *file_name) #define Sys_Free_Memory_Sig(name) void name(void *block) diff --git a/file/4coder_working_set.cpp b/file/4coder_working_set.cpp index d06516e9..4b39e779 100644 --- a/file/4coder_working_set.cpp +++ b/file/4coder_working_set.cpp @@ -116,7 +116,7 @@ working_set_alloc(Working_Set *working_set){ } internal Editing_File* -working_set_alloc_always(System_Functions *system, Working_Set *working_set, General_Memory *general){ +working_set_alloc_always(Working_Set *working_set, General_Memory *general){ Editing_File *result = 0; Editing_File *new_chunk; i32 full_new_count = working_set->file_max; @@ -126,7 +126,7 @@ working_set_alloc_always(System_Functions *system, Working_Set *working_set, Gen else new_count = (i16)full_new_count; if (working_set->file_count == working_set->file_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); } result = working_set_alloc(working_set); @@ -185,7 +185,7 @@ working_set_get_active_file(Working_Set *working_set, i32 id){ } internal void -working_set_init(System_Functions *system, Working_Set *working_set, Partition *partition, General_Memory *general){ +working_set_init(Working_Set *working_set, Partition *partition, General_Memory *general){ i16 init_count = 16; i16 array_init_count = 256; @@ -211,7 +211,7 @@ working_set_init(System_Functions *system, Working_Set *working_set, Partition * 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(system, general, mem_size); + void *mem = general_memory_allocate(general, mem_size); memset(mem, 0, mem_size); table_init_memory(&working_set->canon_table, mem, table_size, item_size); } @@ -221,23 +221,23 @@ working_set_init(System_Functions *system, Working_Set *working_set, Partition * 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(system, general, mem_size); + void *mem = general_memory_allocate(general, 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(System_Functions *system, Table *table, General_Memory *general, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){ +working_set__grow_if_needed(Table *table, General_Memory *general, 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(system, general, mem_size); + void *mem = general_memory_allocate(general, 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(system, general, table->hash_array); + general_memory_free(general, table->hash_array); *table = btable; } } @@ -256,8 +256,8 @@ working_set_contains_basic(Working_Set *working_set, Table *table, String name){ } internal b32 -working_set_add_basic(System_Functions *system, General_Memory *general, Working_Set *working_set, Table *table, Editing_File *file, String name){ - working_set__grow_if_needed(system, table, general, 0, tbl_string_hash, tbl_string_compare); +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); File_Name_Entry entry; entry.name = name; @@ -279,9 +279,8 @@ working_set_canon_contains(Working_Set *working_set, String name){ } internal b32 -working_set_canon_add(System_Functions *system, General_Memory *general, Working_Set *working_set, - Editing_File *file, String name){ - b32 result = working_set_add_basic(system, general,working_set, &working_set->canon_table, file, name); +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); return(result); } @@ -298,9 +297,8 @@ working_set_name_contains(Working_Set *working_set, String name){ } internal b32 -working_set_name_add(System_Functions *system, General_Memory *general, Working_Set *working_set, - Editing_File *file, String name){ - b32 result = working_set_add_basic(system, general, working_set, &working_set->name_table, file, name); +working_set_name_add(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); return(result); } @@ -435,8 +433,8 @@ buffer_bind_file(System_Functions *system, General_Memory *general, Working_Set file->canon.name = make_fixed_width_string(file->canon.name_); copy_ss(&file->canon.name, canon_filename); terminate_with_null(&file->canon.name); - system->add_listener(file->canon.name_); - b32 result = working_set_canon_add(system, general, working_set, file, file->canon.name); + system->add_listener(file->canon.name.str); + b32 result = working_set_canon_add(general, working_set, file, file->canon.name); Assert(result); AllowLocal(result); } @@ -453,7 +451,7 @@ buffer_unbind_file(System_Functions *system, Working_Set *working_set, Editing_F } internal void -buffer_bind_name(System_Functions *system, General_Memory *general, Working_Set *working_set, Editing_File *file, String filename){ +buffer_bind_name(General_Memory *general, Working_Set *working_set, Editing_File *file, String filename){ Assert(file->name.live_name.size == 0 && file->name.source_path.size == 0 && file->name.extension.size == 0); @@ -467,7 +465,7 @@ buffer_bind_name(System_Functions *system, General_Memory *general, Working_Set copy_ss(&file->name.source_path, new_name.source_path); copy_ss(&file->name.extension, new_name.extension); - b32 result = working_set_name_add(system, general, working_set, file, file->name.live_name); + b32 result = working_set_name_add(general, working_set, file, file->name.live_name); Assert(result); AllowLocal(result); } diff --git a/linux_4ed.cpp b/linux_4ed.cpp index 8d84567d..9d060e75 100644 --- a/linux_4ed.cpp +++ b/linux_4ed.cpp @@ -133,7 +133,7 @@ struct Application_Links; #define InterlockedCompareExchange(dest, ex, comp) __sync_val_compare_and_swap((dest), (comp), (ex)) #include "filetrack/4tech_file_track_linux.c" -#include "system_shared.h" +#include "4ed_system_shared.h" // // Linux structs / enums @@ -1338,7 +1338,7 @@ INTERNAL_Sys_Get_Thread_States_Sig(internal_get_thread_states){ // Linux rendering/font system functions // -#include "system_shared.cpp" +#include "4ed_system_shared.cpp" #include "linux_font.cpp" internal f32 diff --git a/pens_arena.cpp b/pens_arena.cpp new file mode 100644 index 00000000..1f6c46f8 --- /dev/null +++ b/pens_arena.cpp @@ -0,0 +1,14 @@ +/* +Build target for the 'pens' project. +By Allen Webster +Created 09.01.2017 (dd.mm.yyyy) +*/ + +// TOP + +struct Arena{ + +}; + +// BOTTOM + diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index c3cb21bf..cb2d37e1 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -14,6 +14,17 @@ #include +static float +get_line_y(Application_Links *app, View_Summary *view, int32_t line){ + Full_Cursor cursor = {0}; + view_compute_cursor(app, view, seek_line_char(line, 1), &cursor); + float y = cursor.wrapped_y; + if (view->unwrapped_lines){ + y = cursor.unwrapped_y; + } + return(y); +} + CUSTOM_COMMAND_SIG(kill_rect){ View_Summary view = get_active_view(app, AccessOpen); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); @@ -26,10 +37,10 @@ CUSTOM_COMMAND_SIG(kill_rect){ int32_t start = 0; int32_t end = 0; - bool32 success = 1; + bool32 success = 1; Full_Cursor cursor = {0}; - float y = (line-1) * view.line_height; + float y = get_line_y(app, &view, line); if (success){ success = view_compute_cursor(app, &view, seek_xy((float)rect.x0, y, 0, unwrapped), &cursor); @@ -48,7 +59,7 @@ CUSTOM_COMMAND_SIG(kill_rect){ } static void -pad_buffer_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int line, char padchar, int target){ +pad_buffer_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line, char padchar, int32_t target){ Partial_Cursor start = {0}; Partial_Cursor end = {0}; @@ -57,7 +68,7 @@ pad_buffer_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, if (start.line == line){ if (end.character-1 < target){ Temp_Memory temp = begin_temp_memory(part); - int size = target - (end.character-1); + int32_t size = target - (end.character-1); char *str = push_array(part, char, size); memset(str, ' ', size); buffer_replace_range(app, buffer, end.pos, end.pos, str, size); @@ -111,14 +122,14 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Rect rect = get_rect(&view); - int start_line = view.cursor.line; - int pos = view.cursor.character-1; + int32_t start_line = view.cursor.line; + int32_t pos = view.cursor.character-1; - for (int i = rect.line0; i <= rect.line1; ++i){ + for (int32_t i = rect.line0; i <= rect.line1; ++i){ pad_buffer_line(app, &global_part, &buffer, i, ' ', pos); } - int line_count = rect.line1 - rect.line0 + 1; + int32_t line_count = rect.line1 - rect.line0 + 1; for (;;){ User_Input in = get_user_input(app, EventOnAnyKey, EventOnEsc | EventOnButton); @@ -131,7 +142,7 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Edit *edit = push_array(part, Buffer_Edit, line_count); Buffer_Edit *edits = edit; - for (int i = rect.line0; i <= rect.line1; ++i){ + for (int32_t i = rect.line0; i <= rect.line1; ++i){ Partial_Cursor cursor = {0}; if (buffer_compute_cursor(app, &buffer, seek_line_char(i, pos+1), &cursor)){ @@ -143,7 +154,7 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ } } - int edit_count = (int)(edit - edits); + int32_t edit_count = (int)(edit - edits); buffer_batch_edit(app, &buffer, &str, 1, edits, edit_count, BatchEdit_Normal); end_temp_memory(temp); @@ -159,7 +170,7 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Edit *edit = push_array(part, Buffer_Edit, line_count); Buffer_Edit *edits = edit; - for (int i = rect.line0; i <= rect.line1; ++i){ + for (int32_t i = rect.line0; i <= rect.line1; ++i){ Partial_Cursor cursor = {0}; if (buffer_compute_cursor(app, &buffer, seek_line_char(i, pos+1), &cursor)){ @@ -171,7 +182,7 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ } } - int edit_count = (int)(edit - edits); + int32_t edit_count = (int)(edit - edits); buffer_batch_edit(app, &buffer, 0, 0, edits, edit_count, BatchEdit_Normal); end_temp_memory(temp); @@ -186,130 +197,785 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ } } -// TODO(allen): Both of these brace related commands would work better -// if the API exposed access to the tokens in a code file. -CUSTOM_COMMAND_SIG(mark_matching_brace){ +// +// Declaration list +// + +static void +list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buffer){ + String search_name = make_lit_string("*decls*"); + Buffer_Summary decls_buffer = get_buffer_by_name(app, search_name.str, search_name.size, AccessAll); + if (!decls_buffer.exists){ + decls_buffer = create_buffer(app, search_name.str, search_name.size, BufferCreate_AlwaysNew); + buffer_set_setting(app, &decls_buffer, BufferSetting_Unimportant, true); + buffer_set_setting(app, &decls_buffer, BufferSetting_ReadOnly, true); + buffer_set_setting(app, &decls_buffer, BufferSetting_WrapLine, false); + } + else{ + buffer_replace_range(app, &decls_buffer, 0, decls_buffer.size, 0, 0); + } + + Temp_Memory temp = begin_temp_memory(part); + + struct Function_Positions{ + int32_t sig_start_index; + int32_t sig_end_index; + int32_t open_paren_pos; + }; + + Function_Positions *positions_array = push_array(part, Function_Positions, (4<<10)/sizeof(Function_Positions)); + int32_t positions_count = 0; + + Partition extra_memory_ = partition_sub_part(part, (4<<10)); + Partition *extra_memory = &extra_memory_; + char *str = (char*)partition_current(part); + int32_t part_size = 0; + int32_t size = 0; + + static const int32_t token_chunk_size = 512; + Cpp_Token token_chunk[token_chunk_size]; + Stream_Tokens token_stream = {0}; + + if (init_stream_tokens(&token_stream, app, buffer, 0, token_chunk, token_chunk_size)){ + Stream_Tokens start_position_stream_temp = begin_temp_stream_token(&token_stream); + + int32_t token_index = 0; + int32_t nest_level = 0; + int32_t paren_nest_level = 0; + + int32_t first_paren_index = 0; + int32_t first_paren_position = 0; + int32_t last_paren_index = 0; + + bool32 still_looping = false; + + // Look for the next token at global scope that might need to be printed. + mode1: do{ + for (; token_index < token_stream.end; ++token_index){ + Cpp_Token *token = &token_stream.tokens[token_index]; + + if (!(token->flags & CPP_TFLAG_PP_BODY)){ + switch (token->type){ + case CPP_TOKEN_BRACE_OPEN: + { + ++nest_level; + }break; + + case CPP_TOKEN_BRACE_CLOSE: + { + if (nest_level > 0){ + --nest_level; + } + }break; + + case CPP_TOKEN_PARENTHESE_OPEN: + { + if (nest_level == 0){ + first_paren_index = token_index; + first_paren_position = token->start; + goto paren_mode1; + } + }break; + } + } + } + still_looping = forward_stream_tokens(&token_stream); + }while(still_looping); + goto end; + + // Look for a closing parenthese to mark the end of a function signature. + paren_mode1: + paren_nest_level = 0; + do{ + for (; token_index < token_stream.end; ++token_index){ + Cpp_Token *token = &token_stream.tokens[token_index]; + + if (!(token->flags & CPP_TFLAG_PP_BODY)){ + switch (token->type){ + case CPP_TOKEN_PARENTHESE_OPEN: + { + ++paren_nest_level; + }break; + + case CPP_TOKEN_PARENTHESE_CLOSE: + { + --paren_nest_level; + if (paren_nest_level == 0){ + last_paren_index = token_index; + goto paren_mode2; + } + }break; + } + } + } + still_looping = forward_stream_tokens(&token_stream); + }while(still_looping); + goto end; + + // Look backwards from an open parenthese to find the start of a function signature. + paren_mode2: { + Stream_Tokens backward_stream_temp = begin_temp_stream_token(&token_stream); + int32_t local_index = first_paren_index; + int32_t signature_start_index = 0; + + do{ + for (; local_index >= token_stream.start; --local_index){ + Cpp_Token *token = &token_stream.tokens[local_index]; + if ((token->flags & CPP_TFLAG_PP_BODY) || (token->flags & CPP_TFLAG_PP_DIRECTIVE) || token->type == CPP_TOKEN_BRACE_CLOSE || token->type == CPP_TOKEN_SEMICOLON || token->type == CPP_TOKEN_PARENTHESE_CLOSE){ + ++local_index; + signature_start_index = local_index; + goto paren_mode2_done; + } + } + still_looping = backward_stream_tokens(&token_stream); + }while(still_looping); + // When this loop ends by going all the way back to the beginning set the signature start to 0 and fall through to the printing phase. + signature_start_index = 0; + + paren_mode2_done:; + { + Function_Positions positions; + positions.sig_start_index = signature_start_index; + positions.sig_end_index = last_paren_index; + positions.open_paren_pos = first_paren_position; + positions_array[positions_count++] = positions; + } + + end_temp_stream_token(&token_stream, backward_stream_temp); + goto mode1; + } + + end:; + end_temp_stream_token(&token_stream, start_position_stream_temp); + // Print the results + String buffer_name = make_string(buffer->buffer_name, buffer->buffer_name_len); + for (int32_t i = 0; i < positions_count; ++i){ + Function_Positions *positions = &positions_array[i]; + Temp_Memory extra_temp = begin_temp_memory(extra_memory); + + int32_t local_index = positions->sig_start_index; + int32_t end_index = positions->sig_end_index; + int32_t open_paren_pos = positions->open_paren_pos; + + do{ + for (; local_index < token_stream.end; ++local_index){ + Cpp_Token *token = &token_stream.tokens[local_index]; + if (!(token->flags & CPP_TFLAG_PP_BODY)){ + if (token->type != CPP_TOKEN_COMMENT){ + bool32 delete_space_before = false; + bool32 space_after = false; + + switch (token->type){ + case CPP_TOKEN_COMMA: + case CPP_TOKEN_PARENTHESE_OPEN: + case CPP_TOKEN_PARENTHESE_CLOSE: + { + delete_space_before = true; + }break; + } + + switch (token->type){ + case CPP_TOKEN_IDENTIFIER: + case CPP_TOKEN_COMMA: + case CPP_TOKEN_STAR: + { + space_after = true; + }break; + } + if (token->flags & CPP_TFLAG_IS_KEYWORD){ + space_after = true; + } + + if (delete_space_before){ + int32_t pos = extra_memory->pos - 1; + char *base = ((char*)(extra_memory->base)); + if (pos >= 0 && base[pos] == ' '){ + extra_memory->pos = pos; + } + } + + char *token_str = push_array(extra_memory, char, token->size + space_after); + + buffer_read_range(app, buffer, token->start, token->start + token->size, token_str); + if (space_after){ + token_str[token->size] = ' '; + } + } + } + + if (local_index == end_index){ + goto finish_print; + } + } + still_looping = forward_stream_tokens(&token_stream); + }while(still_looping); + + finish_print:; + { + int32_t sig_size = extra_memory->pos; + String sig = make_string(extra_memory->base, sig_size); + + int32_t line_number = buffer_get_line_index(app, buffer, open_paren_pos); + int32_t line_number_len = int_to_str_size(line_number); + + int32_t append_len = buffer_name.size + 1 + line_number_len + 1 + 1 + sig_size + 1; + + char *out_space = push_array(part, char, append_len); + if (out_space == 0){ + buffer_replace_range(app, &decls_buffer, size, size, str, part_size); + size += part_size; + + end_temp_memory(temp); + temp = begin_temp_memory(part); + + part_size = 0; + out_space = push_array(part, char, append_len); + } + + part_size += append_len; + String out = make_string(out_space, 0, append_len); + append(&out, buffer_name); + append(&out, ':'); + append_int_to_str(&out, line_number); + append(&out, ':'); + append(&out, ' '); + append(&out, sig); + append(&out, '\n'); + } + + end_temp_memory(extra_temp); + } + + buffer_replace_range(app, &decls_buffer, size, size, str, part_size); + + View_Summary view = get_active_view(app, AccessAll); + view_set_buffer(app, &view, decls_buffer.buffer_id, 0); + + lock_jump_buffer(search_name.str, search_name.size); + + end_temp_memory(temp); + } +} + +CUSTOM_COMMAND_SIG(list_all_functions_current_buffer){ + uint32_t access = AccessProtected; + View_Summary view = get_active_view(app, access); + Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); + list_all_functions(app, &global_part, &buffer); +} + +// +// Scope-Smart Editing Basics +// + +enum{ + FindScope_Parent = 0x1, + FindScope_NextSibling = 0x1, + FindScope_EndOfToken = 0x2, +}; + +static bool32 +find_scope_top(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ + Cpp_Get_Token_Result get_result = {0}; + + bool32 success = 0; + int32_t position = 0; + + if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ + int32_t token_index = get_result.token_index; + if (flags & FindScope_Parent){ + --token_index; + if (get_result.in_whitespace){ + ++token_index; + } + } + + if (token_index >= 0){ + static const int32_t chunk_cap = 512; + Cpp_Token chunk[chunk_cap]; + Stream_Tokens stream = {0}; + + if (init_stream_tokens(&stream, app, buffer, token_index, chunk, chunk_cap)){int32_t nest_level = 0; + bool32 still_looping = 0; + do{ + for (; token_index >= stream.start; --token_index){ + Cpp_Token *token = &stream.tokens[token_index]; + + switch (token->type){ + case CPP_TOKEN_BRACE_OPEN: + { + if (nest_level == 0){ + success = 1; + position = token->start; + if (flags & FindScope_EndOfToken){ + position += token->size; + } + goto finished; + } + else{ + --nest_level; + } + }break; + + case CPP_TOKEN_BRACE_CLOSE: + { + ++nest_level; + }break; + } + } + still_looping = backward_stream_tokens(&stream); + }while(still_looping); + } + } + } + + finished:; + *end_pos_out = position; + return(success); +} + +static bool32 +find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ + Cpp_Get_Token_Result get_result = {0}; + + bool32 success = 0; + int32_t position = 0; + + if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ + int32_t token_index = get_result.token_index+1; + if (flags & FindScope_Parent){ + --token_index; + if (get_result.in_whitespace){ + ++token_index; + } + } + + if (token_index >= 0){ + static const int32_t chunk_cap = 512; + Cpp_Token chunk[chunk_cap]; + Stream_Tokens stream = {0}; + + if (init_stream_tokens(&stream, app, buffer, token_index, chunk, chunk_cap)){ + int32_t nest_level = 0; + bool32 still_looping = 0; + do{ + for (; token_index < stream.end; ++token_index){ + Cpp_Token *token = &stream.tokens[token_index]; + + switch (token->type){ + case CPP_TOKEN_BRACE_OPEN: + { + ++nest_level; + }break; + + case CPP_TOKEN_BRACE_CLOSE: + { + if (nest_level == 0){ + success = 1; + position = token->start; + if (flags & FindScope_EndOfToken){ + position += token->size; + } + goto finished; + } + else{ + --nest_level; + } + }break; + } + } + still_looping = forward_stream_tokens(&stream); + }while(still_looping); + } + } + } + + finished:; + *end_pos_out = position; + return(success); +} + +static bool32 +find_next_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ + Cpp_Get_Token_Result get_result = {0}; + + bool32 success = 0; + int32_t position = 0; + + if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ + int32_t token_index = get_result.token_index+1; + + if (token_index >= 0){ + static const int32_t chunk_cap = 512; + Cpp_Token chunk[chunk_cap]; + Stream_Tokens stream = {0}; + + if (init_stream_tokens(&stream, app, buffer, token_index, chunk, chunk_cap)){ + if (flags & FindScope_NextSibling){ + int32_t nest_level = 1; + + bool32 still_looping = 0; + do{ + for (; token_index < stream.end; ++token_index){ + Cpp_Token *token = &stream.tokens[token_index]; + + switch (token->type){ + case CPP_TOKEN_BRACE_OPEN: + { + if (nest_level == 0){ + success = 1; + position = token->start; + if (flags & FindScope_EndOfToken){ + position += token->size; + } + goto finished; + } + else{ + ++nest_level; + } + }break; + + case CPP_TOKEN_BRACE_CLOSE: + { + --nest_level; + if (nest_level == -1){ + position = start_pos; + goto finished; + } + }break; + } + } + still_looping = forward_stream_tokens(&stream); + }while(still_looping); + } + else{ + bool32 still_looping = 0; + do{ + for (; token_index < stream.end; ++token_index){ + Cpp_Token *token = &stream.tokens[token_index]; + + if (token->type == CPP_TOKEN_BRACE_OPEN){ + success = 1; + position = token->start; + if (flags & FindScope_EndOfToken){ + position += token->size; + } + goto finished; + } + } + still_looping = forward_stream_tokens(&stream); + }while(still_looping); + } + } + } + } + + finished:; + *end_pos_out = position; + return(success); +} + +static bool32 +find_prev_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ + Cpp_Get_Token_Result get_result = {0}; + + bool32 success = 0; + int32_t position = 0; + + if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ + int32_t token_index = get_result.token_index-1; + + if (token_index >= 0){ + static const int32_t chunk_cap = 512; + Cpp_Token chunk[chunk_cap]; + Stream_Tokens stream = {0}; + + if (init_stream_tokens(&stream, app, buffer, token_index, chunk, chunk_cap)){ + if (flags & FindScope_NextSibling){ + int32_t nest_level = -1; + bool32 still_looping = 0; + do{ + for (; token_index >= stream.start; --token_index){ + Cpp_Token *token = &stream.tokens[token_index]; + + switch (token->type){ + case CPP_TOKEN_BRACE_OPEN: + { + if (nest_level == -1){ + position = start_pos; + goto finished; + } + else if (nest_level == 0){ + success = 1; + position = token->start; + if (flags & FindScope_EndOfToken){ + position += token->size; + } + goto finished; + } + else{ + --nest_level; + } + }break; + + case CPP_TOKEN_BRACE_CLOSE: + { + ++nest_level; + }break; + } + } + still_looping = backward_stream_tokens(&stream); + }while(still_looping); + } + else{ + bool32 still_looping = 0; + do{ + for (; token_index >= stream.start; --token_index){ + Cpp_Token *token = &stream.tokens[token_index]; + + if (token->type == CPP_TOKEN_BRACE_OPEN){ + success = 1; + position = token->start; + if (flags & FindScope_EndOfToken){ + position += token->size; + } + goto finished; + } + } + still_looping = backward_stream_tokens(&stream); + }while(still_looping); + } + } + } + } + + finished:; + *end_pos_out = position; + return(success); +} + +static void +view_set_to_region(Application_Links *app, View_Summary *view, int32_t major_pos, int32_t minor_pos, float normalized_threshold){ + Range range = make_range(major_pos, minor_pos); + bool32 bottom_major = false; + if (major_pos == range.max){ + bottom_major = true; + } + + Full_Cursor top, bottom; + if (view_compute_cursor(app, view, seek_pos(range.min), &top)){ + if (view_compute_cursor(app, view, seek_pos(range.max), &bottom)){ + float top_y = top.wrapped_y; + float bottom_y = bottom.wrapped_y; + if (view->unwrapped_lines){ + top_y = top.unwrapped_y; + bottom_y = bottom.unwrapped_y; + } + + GUI_Scroll_Vars scroll = view->scroll_vars; + float half_view_height = .5f*(float)(view->file_region.y1 - view->file_region.y0); + float threshold = normalized_threshold * half_view_height; + float current_center_y = ((float)scroll.target_y) + half_view_height; + + if (top_y < current_center_y - threshold || bottom_y > current_center_y + threshold){ + float center_target_y = .5f*(top_y + bottom_y); + + if (bottom_major){ + if (center_target_y < bottom_y - half_view_height * .9f){ + center_target_y = bottom_y - half_view_height * .9f; + } + } + else{ + if (center_target_y > top_y + half_view_height * .9f){ + center_target_y = top_y + half_view_height * .9f; + } + } + + float target_y = center_target_y - half_view_height; + if (target_y < 0){ + target_y = 0; + } + + scroll.target_y = (int32_t)(target_y); + view_set_scroll(app, view, scroll); + } + } + } +} + +static float scope_center_threshold = 0.75f; + +CUSTOM_COMMAND_SIG(highlight_surroundng_scope){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - // NOTE(allen): The user provides the memory that the chunk uses, - // this chunk will then be filled at each step of the text stream loop. - // This way you can look for something that should be nearby without - // having to copy the whole file in at once. - Stream_Chunk chunk = {0}; - char chunk_space[(1 << 10)]; - - int32_t result = 0; - int32_t found_result = 0; - - int32_t i = view.cursor.pos; - int32_t still_looping = 1; - int32_t nesting_counter = 0; - char at_cursor = 0; - - if (init_stream_chunk(&chunk, app, &buffer, i, - chunk_space, sizeof(chunk_space))){ - - // NOTE(allen): This is important! The data array is a pointer that is adjusted - // so that indexing it with "i" will put it with the chunk that is actually loaded. - // If i goes below chunk.start or above chunk.end _that_ is an invalid access. - at_cursor = chunk.data[i]; - if (at_cursor == '{'){ - ++i; - do{ - for (; i < chunk.end; ++i){ - at_cursor = chunk.data[i]; - if (at_cursor == '{'){ - ++nesting_counter; - } - else if (at_cursor == '}'){ - if (nesting_counter == 0){ - found_result = 1; - result = i; - goto finished; - } - else{ - --nesting_counter; - } - } - } - still_looping = forward_stream_chunk(&chunk); - } - while (still_looping); + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; + if (find_scope_top(app, &buffer, start_pos, FindScope_Parent, &top)){ + view_set_cursor(app, &view, seek_pos(top), true); + if (find_scope_bottom(app, &buffer, start_pos, FindScope_Parent | FindScope_EndOfToken, &bottom)){ + view_set_mark(app, &view, seek_pos(bottom)); + view_set_to_region(app, &view, top, bottom, scope_center_threshold); } - else if (at_cursor == '}'){ - --i; - do{ - for (; i >= chunk.start; --i){ - at_cursor = chunk.data[i]; - if (at_cursor == '}'){ - ++nesting_counter; - } - else if (at_cursor == '{'){ - if (nesting_counter == 0){ - found_result = 1; - result = i; - goto finished; - } - else{ - --nesting_counter; - } - } - } - still_looping = backward_stream_chunk(&chunk); - } - while (still_looping); + else{ + view_set_to_region(app, &view, top, top, scope_center_threshold); } } - - finished:; - if (found_result){ - view_set_mark(app, &view, seek_pos(result+1)); - } } -CUSTOM_COMMAND_SIG(cursor_to_surrounding_scope){ - unsigned int access = AccessProtected; +// TODO(allen): These aren't super top notch yet (the ones about children and siblings). I am not sure I want them around anyway, because it's not that fluid feeling even when it works. +CUSTOM_COMMAND_SIG(highlight_first_child_scope){ + uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - Stream_Chunk chunk = {0}; - char chunk_space[(1 << 10)]; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; + if (find_next_scope(app, &buffer, start_pos, 0, &top)){ + if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ + view_set_cursor(app, &view, seek_pos(top), true); + view_set_mark(app, &view, seek_pos(bottom)); + view_set_to_region(app, &view, top, bottom, scope_center_threshold); + } + } +} + +CUSTOM_COMMAND_SIG(highlight_next_sibling_scope){ + uint32_t access = AccessProtected; + View_Summary view = get_active_view(app, access); + Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t result = 0; - int32_t found_result = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; + if (find_next_scope(app, &buffer, start_pos, FindScope_NextSibling, &top)){ + if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ + view_set_cursor(app, &view, seek_pos(top), true); + view_set_mark(app, &view, seek_pos(bottom)); + view_set_to_region(app, &view, top, bottom, scope_center_threshold); + } + } +} + +CUSTOM_COMMAND_SIG(highlight_prev_sibling_scope){ + uint32_t access = AccessProtected; + View_Summary view = get_active_view(app, access); + Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t i = view.cursor.pos - 1; - int32_t still_looping = 1; - int32_t nesting_counter = 0; - char at_cursor = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; + if (find_prev_scope(app, &buffer, start_pos, FindScope_NextSibling, &top)){ + if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ + view_set_cursor(app, &view, seek_pos(top), true); + view_set_mark(app, &view, seek_pos(bottom)); + view_set_to_region(app, &view, top, bottom, scope_center_threshold); + } + } +} + +CUSTOM_COMMAND_SIG(highlight_next_scope_absolute){ + uint32_t access = AccessProtected; + View_Summary view = get_active_view(app, access); + Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - if (init_stream_chunk(&chunk, app, &buffer, i, chunk_space, sizeof(chunk_space))){ - do{ - for (; i >= chunk.start; --i){ - at_cursor = chunk.data[i]; - if (at_cursor == '}'){ - ++nesting_counter; - } - else if (at_cursor == '{'){ - if (nesting_counter == 0){ - found_result = 1; - result = i; - goto finished; - } - else{ - --nesting_counter; - } - } - } - still_looping = backward_stream_chunk(&chunk); - } while(still_looping); + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; + if (find_next_scope(app, &buffer, start_pos, 0, &top)){ + if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ + view_set_cursor(app, &view, seek_pos(top), true); + view_set_mark(app, &view, seek_pos(bottom)); + view_set_to_region(app, &view, top, bottom, scope_center_threshold); + } + } +} + +CUSTOM_COMMAND_SIG(highlight_prev_scope_absolute){ + uint32_t access = AccessProtected; + View_Summary view = get_active_view(app, access); + Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); + + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; + if (find_prev_scope(app, &buffer, start_pos, 0, &top)){ + if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ + view_set_cursor(app, &view, seek_pos(top), true); + view_set_mark(app, &view, seek_pos(bottom)); + view_set_to_region(app, &view, top, bottom, scope_center_threshold); + } + } +} + +CUSTOM_COMMAND_SIG(place_in_scope){ + uint32_t access = AccessOpen; + View_Summary view = get_active_view(app, access); + Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); + + Range lines; + Range range = get_range(&view); + lines.min = buffer_get_line_index(app, &buffer, range.min); + range.min = buffer_get_line_start(app, &buffer, lines.min); + + lines.max = buffer_get_line_index(app, &buffer, range.max); + range.max = buffer_get_line_end(app, &buffer, lines.max); + + bool32 do_full = false; + + if (lines.min < lines.max){ + do_full = true; + } + else if (!buffer_line_is_blank(app, &buffer, lines.min)){ + do_full = true; } - finished:; - if (found_result){ - view_set_cursor(app, &view, seek_pos(result), 1); + if (do_full){ + Buffer_Edit edits[2]; + char str[5] = "{\n\n}"; + + int32_t min_adjustment = 0; + int32_t max_adjustment = 4; + + if (buffer_line_is_blank(app, &buffer, lines.min)){ + str[0] = '\n'; + str[1] = '{'; + ++min_adjustment; + } + + if (buffer_line_is_blank(app, &buffer, lines.max)){ + str[2] = '}'; + str[3] = '\n'; + --max_adjustment; + } + + int32_t min_pos = range.min + min_adjustment; + int32_t max_pos = range.max + max_adjustment; + + int32_t cursor_pos = min_pos; + int32_t mark_pos = max_pos; + + if (view.cursor.pos > view.mark.pos){ + cursor_pos = max_pos; + mark_pos = min_pos; + } + + edits[0].str_start = 0; + edits[0].len = 2; + edits[0].start = range.min; + edits[0].end = range.min; + + edits[1].str_start = 2; + edits[1].len = 2; + edits[1].start = range.max; + edits[1].end = range.max; + + buffer_batch_edit(app, &buffer, str, 4, edits, 2, BatchEdit_Normal); + + view_set_cursor(app, &view, seek_pos(cursor_pos), true); + view_set_mark(app, &view, seek_pos(mark_pos)); + } + else{ + buffer_replace_range(app, &buffer, range.min, range.max, "{\n\n}", 4); + view_set_cursor(app, &view, seek_pos(range.min + 2), true); + view_set_mark(app, &view, seek_pos(range.min + 2)); } } @@ -327,10 +993,11 @@ CUSTOM_COMMAND_SIG(rename_parameter){ Cpp_Get_Token_Result result; if (buffer_get_token_index(app, &buffer, view.cursor.pos, &result)){ if (!result.in_whitespace){ - Cpp_Token stream_space[32]; + static const int32_t stream_space_size = 512; + Cpp_Token stream_space[stream_space_size]; Stream_Tokens stream = {0}; - if (init_stream_tokens(&stream, app, &buffer, result.token_index, stream_space, 32)){ + if (init_stream_tokens(&stream, app, &buffer, result.token_index, stream_space, stream_space_size)){ int32_t token_index = result.token_index; Cpp_Token token = stream.tokens[token_index]; @@ -342,12 +1009,10 @@ CUSTOM_COMMAND_SIG(rename_parameter){ if (token.size < sizeof(old_lexeme_base)){ Cpp_Token original_token = token; old_lexeme.size = token.size; - buffer_read_range(app, &buffer, token.start, - token.start+token.size, - old_lexeme.str); + buffer_read_range(app, &buffer, token.start, token.start+token.size, old_lexeme.str); int32_t proc_body_found = 0; - int32_t still_looping = 0; + bool32 still_looping = 0; ++token_index; do{ @@ -411,8 +1076,8 @@ CUSTOM_COMMAND_SIG(rename_parameter){ String other_lexeme = make_fixed_width_string(other_lexeme_base); other_lexeme.size = old_lexeme.size; buffer_read_range(app, &buffer, token_ptr->start, - token_ptr->start+token_ptr->size, - other_lexeme.str); + token_ptr->start+token_ptr->size, + other_lexeme.str); if (match(old_lexeme, other_lexeme)){ Buffer_Edit edit; @@ -455,7 +1120,7 @@ CUSTOM_COMMAND_SIG(rename_parameter){ if (closed_correctly){ buffer_batch_edit(app, &buffer, replace_string.str, replace_string.size, - edits, edit_count, BatchEdit_Normal); + edits, edit_count, BatchEdit_Normal); } } } @@ -496,8 +1161,8 @@ CUSTOM_COMMAND_SIG(write_explicit_enum_values){ int32_t still_looping = 0; do{ - for (; seeker_index < seek_stream.end; ++seeker_index){ - Cpp_Token *token_seeker = seek_stream.tokens + seeker_index; + for (; seeker_index < stream.end; ++seeker_index){ + Cpp_Token *token_seeker = stream.tokens + seeker_index; switch (token_seeker->type){ case CPP_TOKEN_BRACE_CLOSE: closed_correctly = 1; @@ -507,7 +1172,7 @@ CUSTOM_COMMAND_SIG(write_explicit_enum_values){ goto finished_seek; } } - still_looping = forward_stream_tokens(&seek_stream); + still_looping = forward_stream_tokens(&stream); }while(still_looping); finished_seek:; end_temp_stream_token(&stream, seek_stream); @@ -600,7 +1265,7 @@ CUSTOM_COMMAND_SIG(write_explicit_enum_values){ finished:; if (closed_correctly){ buffer_batch_edit(app, &buffer, string_base, string.size, - edits, edit_count, BatchEdit_Normal); + edits, edit_count, BatchEdit_Normal); } } } @@ -611,8 +1276,8 @@ CUSTOM_COMMAND_SIG(write_explicit_enum_values){ end_temp_memory(temp); } -extern "C" int -get_bindings(void *data, int size){ +extern "C" int32_t +get_bindings(void *data, int32_t size){ Bind_Helper context_ = begin_bind_helper(data, size); Bind_Helper *context = &context_; @@ -649,15 +1314,18 @@ get_bindings(void *data, int size){ end_map(context); begin_map(context, my_code_map); - bind(context, '[', MDFR_ALT, cursor_to_surrounding_scope); - bind(context, ']', MDFR_ALT, mark_matching_brace); + bind(context, '[', MDFR_ALT, highlight_surroundng_scope); + bind(context, ']', MDFR_ALT, highlight_prev_scope_absolute); + bind(context, '\'', MDFR_ALT, highlight_next_scope_absolute); + bind(context, key_insert, MDFR_CTRL, write_explicit_enum_values); bind(context, 'p', MDFR_ALT, rename_parameter); + bind(context, 'I', MDFR_CTRL, list_all_functions_current_buffer); end_map(context); BIND_4CODER_TESTS(context); - int result = end_bind_helper(context); + int32_t result = end_bind_helper(context); return(result); } diff --git a/project.4coder b/project.4coder index 0be2f5ed..eeb321fb 100644 --- a/project.4coder +++ b/project.4coder @@ -1,34 +1,34 @@ extensions=".c.cpp.h.hpp.bat.sh"; fkey_command_win[1] = {"build.bat", "*compilation*", true}; -fkey_command_win[2] = {"..\\misc\\run.bat", "*run*"}; -fkey_command_win[3] = {"site\\build.bat", "*compilation*", true}; -fkey_command_win[4] = {"file\\run_tests.bat", "*tests*", true}; -fkey_command_win[5] = {0, 0}; +fkey_command_win[2] = {"site\\build.bat", "*compilation*", true}; +fkey_command_win[3] = {"file\\run_tests.bat", "*tests*", true}; +fkey_command_win[4] = {0, 0}; +fkey_command_win[5] = {"..\\misc\\run.bat", "*run*"}; fkey_command_win[6] = {0, 0}; fkey_command_win[7] = {0, 0}; -fkey_command_win[8] = {"package.bat", "*package*"}; +fkey_command_win[8] = {0, 0}; fkey_command_win[9] = {0, 0}; fkey_command_win[10] = {0, 0}; fkey_command_win[11] = {0, 0}; -fkey_command_win[12] = {0, 0}; +fkey_command_win[8] = {"package.bat", "*package*"}; fkey_command_win[13] = {0, 0}; fkey_command_win[14] = {0, 0}; fkey_command_win[15] = {0, 0}; fkey_command_win[16] = {0, 0}; fkey_command_linux[1] = {"./build.sh", "*compilation*", true}; -fkey_command_linux[2] = {"../build/4ed", "*run*"}; -fkey_command_linux[3] = {"site/build.sh", "*compilation*", true}; +fkey_command_linux[2] = {"site/build.sh", "*compilation*", true}; +fkey_command_linux[3] = {0, 0}; fkey_command_linux[4] = {0, 0}; -fkey_command_linux[5] = {0, 0}; +fkey_command_linux[5] = {"../build/4ed", "*run*"}; fkey_command_linux[6] = {0, 0}; fkey_command_linux[7] = {0, 0}; -fkey_command_linux[8] = {"./package.sh", "*package*"}; +fkey_command_linux[8] = {0, 0}; fkey_command_linux[9] = {0, 0}; fkey_command_linux[10] = {0, 0}; fkey_command_linux[11] = {0, 0}; -fkey_command_linux[12] = {0, 0}; +fkey_command_linux[12] = {"./package.sh", "*package*"}; fkey_command_linux[13] = {0, 0}; fkey_command_linux[14] = {0, 0}; fkey_command_linux[15] = {0, 0}; diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 4b698ee1..dba8a8fb 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -69,7 +69,7 @@ struct Application_Links; #define GL_TEXTURE_MAX_LEVEL 0x813D #include "filetrack/4tech_file_track_win32.c" -#include "system_shared.h" +#include "4ed_system_shared.h" #define SUPPORT_DPI 1 #define USE_FT_FONTS 1 @@ -111,7 +111,7 @@ struct Control_Keys{ b8 l_alt; b8 r_alt; }; -static Control_Keys null_control_keys; +static Control_Keys null_control_keys = {0}; struct Win32_Input_Chunk_Transient{ Key_Input_Data key_data; @@ -1221,7 +1221,7 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){ return(close_me); } -#include "system_shared.cpp" +#include "4ed_system_shared.cpp" #if USE_FT_FONTS # include "win32_ft_font.cpp" @@ -1486,10 +1486,8 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ case VK_MENU:case VK_LMENU:case VK_RMENU: case VK_SHIFT:case VK_LSHIFT:case VK_RSHIFT: { - Control_Keys *controls = 0; - b8 *control_keys = 0; - controls = &win32vars.input_chunk.pers.controls; - control_keys = win32vars.input_chunk.pers.control_keys; + Control_Keys *controls = &win32vars.input_chunk.pers.controls; + b8 *control_keys = win32vars.input_chunk.pers.control_keys; b8 down = ((lParam & Bit_31)?(0):(1)); b8 is_right = ((lParam & Bit_24)?(1):(0)); @@ -1722,7 +1720,7 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ win32vars.input_chunk.pers.mouse_l = 0; win32vars.input_chunk.pers.mouse_r = 0; - for (int32_t i = 0; i < MDFR_INDEX_COUNT; ++i){ + for (i32 i = 0; i < MDFR_INDEX_COUNT; ++i){ win32vars.input_chunk.pers.control_keys[i] = 0; } win32vars.input_chunk.pers.controls = null_control_keys; @@ -2091,7 +2089,7 @@ WinMain(HINSTANCE hInstance, PFD_MAIN_PLANE, 0, 0, 0, 0 }; - + // TODO(allen): get an upgraded context to see if that fixes the nvidia card issues. { i32 pixel_format; pixel_format = ChoosePixelFormat(hdc, &pfd);