From 8bd7c2fd679c24a1b9f453caf7cd356eeff50e2d Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Tue, 3 Sep 2019 22:31:35 -0700 Subject: [PATCH] Token transition in progress --- 4coder_API/4coder_custom.h | 2 - 4coder_API/4coder_types.h | 439 +---- 4coder_auto_indent.cpp | 56 +- 4coder_auto_indent.h | 2 +- 4coder_base_commands.cpp | 9 + 4coder_base_types.cpp | 1618 ++++++++------- 4coder_base_types.h | 28 + 4coder_casey_classic.cpp | 1950 ------------------ 4coder_clipboard.cpp | 24 +- 4coder_config.cpp | 9 +- 4coder_config.h | 6 +- 4coder_default_framework.cpp | 38 +- 4coder_default_framework.h | 9 +- 4coder_default_framework_variables.cpp | 23 +- 4coder_default_hooks.cpp | 181 +- 4coder_default_include.cpp | 4 - 4coder_experiments.cpp | 34 +- 4coder_file.h | 2 - 4coder_function_list.cpp | 24 +- 4coder_generated/app_functions.h | 98 +- 4coder_generated/command_metadata.h | 176 +- 4coder_helper.cpp | 377 ++-- 4coder_helper.h | 27 +- 4coder_jump_sticky.cpp | 13 +- 4coder_lib/4coder_heap.cpp | 143 -- 4coder_lib/4coder_heap.h | 43 - 4coder_lib/4coder_string.h | 2498 ------------------------ 4coder_log_parser.cpp | 6 +- 4coder_metadata_generator.cpp | 48 +- 4coder_scope_commands.cpp | 72 +- 4coder_search.cpp | 7 +- 4coder_table.cpp | 10 +- 4coder_ui_helper.cpp | 80 +- 4coder_ui_helper.h | 1 - 4ed.cpp | 31 +- 4ed_api_implementation.cpp | 314 +-- 4ed_app_models.h | 10 +- 4ed_app_target.cpp | 9 - 4ed_cli.cpp | 30 +- 4ed_cli.h | 4 +- 4ed_dynamic_variables.cpp | 594 ++---- 4ed_dynamic_variables.h | 72 +- 4ed_edit.cpp | 31 +- 4ed_file.cpp | 45 +- 4ed_file.h | 7 - 4ed_file_lex.cpp | 212 -- 4ed_history.cpp | 33 +- 4ed_history.h | 3 +- 4ed_memory_bank.cpp | 54 - 4ed_memory_bank.h | 29 - 4ed_parse_context.cpp | 178 -- 4ed_ptr_check.cpp | 361 ---- 4ed_ptr_check.h | 39 - 4ed_view.cpp | 12 +- 4ed_working_set.cpp | 12 +- languages/4coder_language_cpp.h | 20 + languages/4coder_language_cs.h | 2 + languages/4coder_language_java.h | 2 + languages/4coder_language_rust.h | 2 + meta/4ed_meta_parser.cpp | 100 +- meta/4ed_metagen.cpp | 1 - platform_win32/win32_4ed.cpp | 3 - 62 files changed, 1991 insertions(+), 8276 deletions(-) delete mode 100644 4coder_casey_classic.cpp delete mode 100644 4coder_lib/4coder_heap.cpp delete mode 100644 4coder_lib/4coder_heap.h delete mode 100644 4coder_lib/4coder_string.h delete mode 100644 4ed_file_lex.cpp delete mode 100644 4ed_memory_bank.cpp delete mode 100644 4ed_memory_bank.h delete mode 100644 4ed_parse_context.cpp delete mode 100644 4ed_ptr_check.cpp delete mode 100644 4ed_ptr_check.h diff --git a/4coder_API/4coder_custom.h b/4coder_API/4coder_custom.h index 8e22314c..427fad69 100644 --- a/4coder_API/4coder_custom.h +++ b/4coder_API/4coder_custom.h @@ -12,8 +12,6 @@ #include #include "4coder_base_types.h" -#include "4coder_lib/4coder_heap.h" -#include "4coder_lib/4coder_string.h" #include "4coder_lib/4cpp_lexer_types.h" #include "4coder_API/4coder_version.h" #include "4coder_API/4coder_keycodes.h" diff --git a/4coder_API/4coder_types.h b/4coder_API/4coder_types.h index 276e1f9e..01260347 100644 --- a/4coder_API/4coder_types.h +++ b/4coder_API/4coder_types.h @@ -13,23 +13,16 @@ #endif -/* DOC(argb_color is an alias name to signal that an integer parameter or field is for a color value, -colors are specified as 32 bit integers with 4 channels: 0xAARRGGBB.) */ TYPEDEF u32 argb_color; TYPEDEF u32 int_color; TYPEDEF u16 id_color; -/* DOC(Parse_Context_ID identifies a parse context, which is a guiding rule for the parser. Each buffer sets which parse context to use when it is parsed.) */ -TYPEDEF u32 Parse_Context_ID; - TYPEDEF u32 Child_Process_ID; -/* DOC(Buffer_ID is used to name a 4coder buffer. Each buffer has a unique id but when a buffer is closed it's id may be recycled by future, different buffers.) */ TYPEDEF i32 Buffer_ID; -/* DOC(View_ID is used to name a 4coder view. Each view has a unique id in the interval [1,16].) */ TYPEDEF i32 View_ID; TYPEDEF i32 Panel_ID; @@ -58,27 +51,21 @@ ENUM(u32, Child_Process_Set_Target_Flags){ ChildProcessSet_CursorAtEnd = 4, }; -/* DOC(A Key_Modifier_Index acts as an index for specifying modifiers in arrays.) */ ENUM(i32, Key_Modifier_Index){ MDFR_SHIFT_INDEX, MDFR_CONTROL_INDEX, MDFR_ALT_INDEX, MDFR_COMMAND_INDEX, - /* DOC(MDFR_INDEX_BINDABLE_COUNT is used to specify the number of supported modifiers that can be used in key bindings.) */ MDFR_INDEX_BINDABLE_COUNT, MDFR_CAPS_INDEX = MDFR_INDEX_BINDABLE_COUNT, MDFR_HOLD_INDEX, - /* DOC(MDFR_INDEX_COUNT is used to specify the number of modifiers supported.) */ MDFR_INDEX_COUNT }; -/* DOC(A Key_Modifier_Flag field is used to specify a specific state of modifiers. -Flags can be combined with bit or to specify a state with multiple modifiers.) */ ENUM(u32, Key_Modifier_Flag){ - /* DOC(MDFR_NONE specifies that no modifiers are pressed.) */ MDFR_NONE = 0x0, MDFR_CTRL = 0x1, MDFR_ALT = 0x2, @@ -86,79 +73,30 @@ ENUM(u32, Key_Modifier_Flag){ MDFR_SHIFT = 0x8, }; -/* DOC(Flags for describing the memory protection status of pages that come back from memory allocate. Some combinations may not be available on some platforms, but you are gauranteed to get back a page with at least the permissions you requested. For example if you request just write permission, you may get back a page with read and write permission, but you will never get back a page that doesn't have write permission.) */ ENUM(u32, Memory_Protect_Flags){ - /* DOC(Allows the page to be read.) */ MemProtect_Read = 0x1, - /* DOC(Allows the page to be written.) */ MemProtect_Write = 0x2, - /* DOC(Allows the page to be executed.) */ MemProtect_Execute = 0x4, }; -/* DOC(A Wrap_Indicator_Mode is used in the buffer setting BufferSetting_WrapIndicator to specify how to indicate that line has been wrapped.) */ ENUM(i32, Wrap_Indicator_Mode){ - /* DOC(WrapIndicator_Hide tells the buffer rendering system not to put any indicator on wrapped lines.) */ WrapIndicator_Hide, - - /* DOC(WrapIndicator_Show_After_Line tells the buffer rendering system to put a backslash indicator on wrapped lines right after the last character of the line.) */ WrapIndicator_Show_After_Line, - - /* DOC(WrapIndicator_Show_At_Wrap_Edge tells the buffer rendering system to put a backslash indicator on wrapped lines aligned with the wrap position for that line.) */ WrapIndicator_Show_At_Wrap_Edge, }; -/* DOC(A Global_Setting_ID names a setting.) */ ENUM(i32, Global_Setting_ID){ - /* DOC(GlobalSetting_Null is not a valid setting, it is reserved to detect errors.) */ GlobalSetting_Null, - - /* DOC(When GlobalSetting_LAltLCtrlIsAltGr is enabled, keyboard layouts with AltGr will also interpret the left alt and control keys as AltGr. If you do not use a keyboard with AltGr you should have this turned off. This setting is only relevant on Windows and has no effect on other systems.) */ GlobalSetting_LAltLCtrlIsAltGr, }; -/* DOC(A Buffer_Setting_ID names a setting in a buffer.) */ ENUM(i32, Buffer_Setting_ID){ - /* DOC(BufferSetting_Null is not a valid setting, it is reserved to detect errors.) */ BufferSetting_Null, - - /* DOC(The BufferSetting_Lex setting is used to determine whether to store C++ tokens from with the buffer.) */ - BufferSetting_Lex, - - /* DOC(The BufferSetting_LexWithoutStrings tells the system to treat string and character marks as identifiers instead of strings. This settings does nothing if the buffer does not have lexing turned on.) */ - BufferSetting_LexWithoutStrings, - - /* DOC(The BufferSetting_ParserContext setting determines the parser context that guides the parser for the contents of this buffer. By default the value is 0, which represents the default C++ context.) */ - BufferSetting_ParserContext, - - /* DOC(The BufferSetting_WrapLine setting is used to determine whether a buffer prefers to be viewed with wrapped lines, individual views can be set to override this value after being tied to the buffer.) */ - BufferSetting_WrapLine, - - /* DOC(The BufferSetting_WrapPosition setting determines after how many pixels a line will wrap. A view set's this value from the global default value when the view is created. This value cannot be set to less than 48, any value passed below 48 will cause the position to be set to 48. This is a potentially expensive operation because the wrap positions of the file have to be reindexed. For best behavior try to only set this setting once per frame, if possible.) */ - BufferSetting_WrapPosition, - - /* DOC(The BufferSetting_MinimumBaseWrapPosition setting is used to increase the with in pixels allotted to a line for wrapping, by setting a minimum position away from the base of the line. The base of a line is always 0, or the left hand side of the view, in text files. In code files the base of a line is the amount the line is shifted to the right due to brace nesting. This setting allows for deeply nested code to remain readable by ensuring lines deep in the nesting get some minimum base width which may be more wrapping space than the non base adjusted wrap position would have allowed. In any case where the (default wrapping position) is greater than (the base + minimum base position), the larger ) the default will still be used. */ - BufferSetting_MinimumBaseWrapPosition, - - /* DOC(The BufferSetting_WrapIndicator setting is used to specify how wrapped lines should be marked so the user can see that they have been wrapped. The value should be one of the values in the Wrap_Indicator_Mode enum.) DOC_SEE(Wrap_Indicator_Mode) */ - BufferSetting_WrapIndicator, - - /* DOC(The BufferSetting_MapID setting specifies the id of the command map that should be active when a buffer is active.) */ BufferSetting_MapID, - - /* DOC(The BufferSetting_Eol setting specifies how line ends should be saved to the backing file. A 1 indicates dos endings "\r\n" and a 0 indicates nix endings "\n".) */ BufferSetting_Eol, - - /* DOC(The BufferSetting_Unimportant setting marks a buffer so that its dirty state will be forced to stay at DirtyState_UpToDate when the buffer is edited or when the buffer's paired file, if it has one, is edited.) */ BufferSetting_Unimportant, - - /* DOC(The BufferSetting_ReadOnly setting marks a buffer so that it can only be returned from buffer access calls that include an AccessProtected flag. By convention this means that edit commands that should not be applied to read only buffers will not edit this buffer.) */ BufferSetting_ReadOnly, - - /* DOC(The BufferSetting_VirtualWhitespace setting enables virtual whitespace on a buffer. Text buffers with virtual whitespace will set the indentation of every line to zero. Buffers with lexing enabled will use virtual white space to present the code with appealing indentation.) */ BufferSetting_VirtualWhitespace, - - /* DOC(TODO) */ BufferSetting_RecordsHistory, }; @@ -166,196 +104,99 @@ STRUCT Character_Predicate{ u8 b[32]; }; -/* DOC(A View_Setting_ID names an adjustable setting in a view.) */ ENUM(i32, View_Setting_ID){ - /* DOC(ViewSetting_Null is not a valid setting, it is reserved to detect errors.) */ ViewSetting_Null, - - /* DOC(Determines whether the view highlights whitespace in a file. Whenever the view switches to a new buffer this setting is turned off.) */ ViewSetting_ShowWhitespace, - - /* DOC(Determines whether a scroll bar is attached to a view in it's scrollable section.) */ ViewSetting_ShowScrollbar, - - /* DOC(Determines whether to show the file bar.) */ ViewSetting_ShowFileBar, - - /* DOC(Determines what command map the view uses when it is in ui mode.) */ ViewSetting_UICommandMap }; -/* DOC(A Buffer_Create_Flag field specifies how a buffer should be created.) */ ENUM(u32, Buffer_Create_Flag){ - /* DOC(BufferCreate_Background is not currently implemented.) */ BufferCreate_Background = 0x1, - /* DOC(When BufferCreate_AlwaysNew is set it indicates the buffer should be cleared to empty even if it's associated file already has content.) */ BufferCreate_AlwaysNew = 0x2, - /* DOC(When BufferCreate_NeverNew is set it indicates that the buffer should only be created if it is an existing file or if a buffer with the given name is already open.) */ BufferCreate_NeverNew = 0x4, - /* DOC(When BufferCreate_JustChangedFile is set it indicates that the file to load has just been saved in the same frame and a change notification for the file should be ignored.) */ BufferCreate_JustChangedFile = 0x8, - /* DOC(Indicates that when create_buffer searches for already existing buffers that match the name parameter, it should only search by file name, and that if it cannot create the buffer with the file attached, it should not create the buffer at all.) */ BufferCreate_MustAttachToFile = 0x10, - /* DOC(Indicates that when create_buffer searches for already existing buffers that match the name parameter, it should only search by buffer name, and that it should not attach a file to the buffer even if it can. Caution! Buffers that don't have attached files cannot be saved.) */ BufferCreate_NeverAttachToFile = 0x20, - /* DOC(Normally the new file hook is called on any created buffer. Passing this flag will prevent the new file hook from being called automatically by the core.) */ BufferCreate_SuppressNewFileHook = 0x40, }; -/* DOC(Buffer_Creation_Data is a struct used as a local handle for the creation of a buffer. ) -HIDE_MEMBERS() */ -STRUCT Buffer_Creation_Data{ - Buffer_Create_Flag flags; - char fname_space [256]; - i32 fname_len; -}; - -/* DOC(A Buffer_Save_Flag field specifies buffer saving behavior.) */ ENUM(u32, Buffer_Save_Flag){ - /* DOC(BufferSave_IgnoreDirtyFlag tells the save procedure not to check the dirty flag of the buffer. Usually buffers not marked dirty will not be saved, but sometimes it is useful to force it to save anyway. ) */ BufferSave_IgnoreDirtyFlag = 0x1, }; -/* DOC(A Buffer_Kill_Flag field specifies how a buffer should be killed.) */ ENUM(u32, Buffer_Kill_Flag){ - /* DOC(When BufferKill_AlwaysKill is set it indicates the buffer should be killed - without asking, even when the buffer is dirty.) */ BufferKill_AlwaysKill = 0x2, }; -/* DOC(A Buffer_Reopen_Flag field specifies how a buffer should be reopened -- currently no flags are provided.) */ ENUM(u32, Buffer_Reopen_Flag){}; -/* DOC(A status enumeration returned by kill_buffer.) -DOC_SEE(kill_buffer) */ ENUM(i32, Buffer_Kill_Result){ - /* DOC(The buffer was successfully killed.) */ BufferKillResult_Killed = 0, - /* DOC(The buffer was not killed because it is dirty. This can be overriden with the flag BufferKill_AlwaysKill. This result is usually followed up by launching a "sure to kill" dialogue, but that is entirely optional.) */ BufferKillResult_Dirty = 1, - /* DOC(The buffer was not killed because it is unkillable. Unkillable buffers are the buffers that must be open for the core's purposes. *messages* and *scratch* are unkillable buffers.) */ BufferKillResult_Unkillable = 2, - /* DOC(The specified buffer does not exist.) */ BufferKillResult_DoesNotExist = 3, }; -/* DOC(A status enumeration returned by reopen_buffer.) -DOC_SEE(kill_buffer) */ ENUM(i32, Buffer_Reopen_Result){ - /* DOC(The buffer was successfully reopened.) */ BufferReopenResult_Reopened = 0, - /* DOC(The buffer was not reopened, because either the buffer has no attached file, or the attached file could not be loaded.) */ BufferReopenResult_Failed = 1, }; -/* DOC(An Access_Flag field specifies what sort of permission you grant to an access call. An access call is usually one the returns a summary struct. If a 4coder object has a particular protection flag set and the corresponding bit is not set in the access field, that 4coder object is hidden. On the other hand if a protection flag is set in the access parameter and the object does not have that protection flag, the object is still returned from the access call.) */ ENUM(u32, Access_Flag){ - /* DOC(AccessOpen does not include any bits, it indicates that the access should 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 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 instance because it is navigating the file system to open a file.) */ AccessHidden = 0x2, - /* DOC(AccessAll is a catchall access for cases where an access call should always return an object no matter what it's protection flags are.) */ AccessAll = 0xFF }; -/* DOC(A Dirty_State value describes whether changes have been made to a buffer or to an underlying -file since the last sync time between the two. Saving a buffer to it's file or loading the buffer -from the file both act as sync points.) */ ENUM(u32, Dirty_State){ - /* DOC(DirtyState_UpToDate indicates that there are no unsaved changes and the underlying -system file still agrees with the buffer's state.) */ DirtyState_UpToDate = 0, - - /* DOC(DirtyState_UnsavedChanges indicates that there have been changes in the buffer since -the last sync point.) */ DirtyState_UnsavedChanges = 1, - - /* DOC(DirtyStateUnloadedChanges indicates that the underlying file has been edited since -the last sync point .) */ DirtyState_UnloadedChanges = 2, - - /* DOC(TODO) */ DirtyState_UnsavedChangesAndUnloadedChanges = 3, }; -/* DOC(A Command_Line_Interface_Flag field specifies the behavior of a call to a command line interface.) */ ENUM(u32, Command_Line_Interface_Flag){ - /* DOC(If CLI_OverlapWithConflict is set if output buffer of the new command is already in use by another command which is still executing, the older command relinquishes control of the buffer and both operate simultaneously with only the newer command outputting to the buffer.) */ CLI_OverlapWithConflict = 0x1, - /* DOC(If CLI_AlwaysBindToView is set the output buffer will always be set in the active view even if it is already set in another open view.) */ CLI_AlwaysBindToView = 0x2, - /* DOC(If CLI_CursorAtEnd is set the cursor will be kept at the end of the output buffer, otherwise the cursor is kept at the beginning.) */ CLI_CursorAtEnd = 0x4, - /* DOC(TODO) */ CLI_SendEndSignal = 0x8, }; -/* DOC(An Auto_Indent_Flag field specifies the behavior of an auto indentation operation.) */ ENUM(u32, Auto_Indent_Flag){ - /* DOC(If AutoIndent_ClearLine is set, then any line that is only whitespace will be cleared to contain nothing at all, otherwise the line is filled with whitespace to match the nearby indentation.) */ AutoIndent_ClearLine = 0x1, - /* DOC(If AutoIndent_UseTab is set, then when putting in leading whitespace to align code, as many tabs will be used as possible until the fine grained control of spaces is needed to finish the alignment.) */ AutoIndent_UseTab = 0x2, - /* DOC(If AutoIndent_ExactAlignBlock is set, then block comments are indented by putting the first non-whitespace character of the line in line with the beginning of the comment.) */ AutoIndent_ExactAlignBlock = 0x4, - /* DOC(If AutoIndent_FullTokens is set, then the set of lines that are indented is automatically expanded so that any token spanning multiple lines gets entirely indented.) */ AutoIndent_FullTokens = 0x8, }; -/* DOC(A Set_Buffer_Flag field specifies the behavior of an operation that sets the buffer of a view.) */ ENUM(u32, Set_Buffer_Flag){ - /* DOC(If SetBuffer_KeepOriginalGUI then when the file is set, the view will not switch to it - if some other GUI was currently up, otherwise any GUI that is up is closed and the view - switches to the file.) */ SetBuffer_KeepOriginalGUI = 0x1 }; -/* DOC(A Input_Type_Flag field specifies a set of input event types.) */ ENUM(u32, Input_Type_Flag){ - /* DOC(If EventOnAnyKey is set, all keyboard events are included in the set.) */ EventOnAnyKey = 0x1, - /* DOC(If EventOnEsc is set, any press of the escape key is included in the set.) */ EventOnEsc = 0x2, - - /* DOC(If EventOnLeftButton is set, left clicks and releases are included in the set.) */ EventOnMouseLeftButton = 0x4, - /* DOC(If EventOnRightButton is set, right clicks and releases are included in the set.) */ EventOnMouseRightButton = 0x8, - /* DOC(If EventOnWheel is set, any wheel movement is included in the set.) */ EventOnMouseWheel = 0x10, - /* DOC(If EventOnMouseMove is set, mouse movement events are included in the set.) */ EventOnMouseMove = 0x20, - - /* DOC(If EventOnAnimate is set, animate events are included in the set.) */ EventOnAnimate = 0x40, - /* DOC(If EventOnViewActivation is set, view activation and deactivation events are included in the set.) */ EventOnViewActivation = 0x80, - - /* DOC(EventAll is a catch all name for including all possible events in the set.) */ EventAll = 0xFFFFFFFF, }; -/* DOC(A Mouse_Cursor_Show_Type value specifes a mode for 4coder to handle the mouse cursor.) */ ENUM(i32, Mouse_Cursor_Show_Type){ - /* DOC(The MouseCursorShow_Never mode never shows the cursor.) */ MouseCursorShow_Never, - /* DOC(The MouseCursorShow_Never mode always shows the cursor.) */ MouseCursorShow_Always, - // TODO(allen): coming soon - // MouseCursorShow_WhenActive, }; -/* DOC(A View_Split_Position specifies where a new view should be placed as a result of a view split operation.) */ ENUM(i32, View_Split_Position){ - /* DOC(This value indicates that the new view should be above the existing view.) */ ViewSplit_Top, - /* DOC(This value indicates that the new view should be below the existing view.) */ ViewSplit_Bottom, - /* DOC(This value indicates that the new view should be left of the existing view.) */ ViewSplit_Left, - /* DOC(This value indicates that the new view should be right of the existing view.) */ ViewSplit_Right, }; @@ -376,76 +217,43 @@ ENUM(i32, Panel_Child){ PanelChild_Max = 1, }; -/* DOC(Key_Code is the alias for key codes including raw codes and codes translated to textual input that takes modifiers into account.) */ TYPEDEF u32 Key_Code; -/* DOC(Key_Modifier is the alias for flags that represent keyboard modifiers, ctrl, alt, shift, etc.) -DOC_SEE(Key_Modifier_Flag) */ -TYPEDEF uint8_t Key_Modifier; +TYPEDEF u8 Key_Modifier; -/* DOC(Key_Event_Data describes a key event, including the translation to a character, the translation to a character ignoring the state of caps lock, and an array of all the modifiers that were pressed at the time of the event.) -DOC_SEE(Key_Modifier_Index) -*/ STRUCT Key_Event_Data{ - /* DOC(This field is the raw keycode which is always non-zero in valid key events.) */ Key_Code keycode; - - /* DOC(This field is the keycode after translation to a character, this is 0 if there is no translation.) */ Key_Code character; - - /* DOC(This field is like the field character, except that the state of caps lock is ignored in the translation.) */ Key_Code character_no_caps_lock; - - /* DOC(This field is an array indicating the state of modifiers at the time of the key press. The array is indexed using the values of Key_Modifier_Index. -1 indicates that the corresponding modifier was held, and a 0 indicates that it was not held.) -DOC_SEE(Key_Modifier) */ - int8_t modifiers[MDFR_INDEX_COUNT]; + i8 modifiers[MDFR_INDEX_COUNT]; }; -// TODO(allen): GLOBAL_VAR meta parsing GLOBAL_VAR Key_Event_Data null_key_event_data = {}; -/* DOC(Mouse_State describes an entire mouse state complete with the position, left and right button states, the wheel state, and whether or not the mouse if in the window.) */ STRUCT Mouse_State{ - /* DOC(Left button is down.) */ int8_t l; - /* DOC(Right button is down.) */ int8_t r; - /* DOC(Left button was pressed this frame.) */ int8_t press_l; - /* DOC(Right button was pressed this frame.) */ int8_t press_r; - /* DOC(Left button was released this frame.) */ int8_t release_l; - /* DOC(Right button was released this frame.) */ int8_t release_r; - /* DOC(Mouse is outside of the window.) */ int8_t out_of_window; - /* DOC(The motion of the wheel. Zero indicates no motion. Positive indicates downard scrolling. Negative indicates upward scrolling. The magnitude corresponds to the number of pixels of scroll that would be applied at standard scroll speeds.) */ i32 wheel; UNION{ STRUCT{ - /* DOC(X position of the mouse where the left of the window is x = 0, and x grows to the right.) */ i32 x; - /* DOC(Y position of the mouse where the top of the window is y = 0, and y grows to downward.) */ i32 y; }; - /* DOC(TODO) */ Vec2_i32 p; }; }; -/* DOC(Parser_String_And_Type contains a string and type integer used to specify information about keywords to the parser.) */ STRUCT Parser_String_And_Type{ - /* DOC(The string specified by the pair, it need not be null terminated.) */ char *str; - /* DOC(The number of bytes in the string str.) */ u32 length; - /* DOC(The type integer.) */ u32 type; }; -/* DOC(Microsecond_Time_Stamp is a typedef of an unsigned 64 bit integer used to signify that the value is an arbitrary for a moment in time.) */ TYPEDEF u64 Microsecond_Time_Stamp; ENUM(u32, File_Attribute_Flag){ @@ -469,13 +277,9 @@ STRUCT File_List{ u32 count; }; -/* DOC(Buffer_Identifier acts as a loosely typed description of a buffer that can either be a name or an id.) */ STRUCT Buffer_Identifier{ - /* DOC(This field is the name of the buffer; it need not be null terminated. If id is specified this pointer should be NULL.) */ char *name; - /* DOC(This field specifies the length of the name string.) */ i32 name_len; - /* DOC(This field is the id of the buffer. If name is specified this should be 0.) */ Buffer_ID id; }; @@ -532,161 +336,46 @@ STRUCT Range_Cursor{ }; }; -/* -DOC(A markers is a location in a buffer that, once placed, is effected by edits the same way characters are effected. In particular if an edit occurs in a location in the buffer before a marker, the marker is shifted forward or backward so that it remains on the same character.) -DOC_SEE(buffer_add_markers) -*/ STRUCT Marker{ - /* DOC(The current position of the marker measure in absolute byte positioning coordinates.) */ i64 pos; - /* DOC(When a marker is inside a range that gets edited, by default the marker 'leans_left' which means it goes to the beginning of the edited range. If the field lean_right is set to true, the marker will lean right with edits and will go to the end of edited range.) */ b32 lean_right; }; -/* DOC(The enumeration of types of managed objects.) */ ENUM(i32, Managed_Object_Type) { - /* DOC(This type value indicates that the specified object for an operation is not a valid managed object. -A handle for a managed object can "go bad" when it's scope is cleared, or when it is freed, so it is possible to store handles and check them for validity on use. However, all managed object APIs do the necessary checks on their parameters and return appropriate failure results on bad handles.) */ ManagedObjectType_Error = 0, - /* DOC(A memory object is used for straightforward memory allocation in a managed scope. These objects have no special cleanup, no extra operations, and their memory storage is never touched by the core.) */ ManagedObjectType_Memory = 1, - /* DOC(A marker object is used to place markers into buffers that move along with the text upon which they are placed. A marker object has a specific buffer to which it is attached, and must be allocated in a scope dependent upon the lifetime of that buffer. Marker objects always use the Marker type for their items, and their item size is always sizeof(Marker). When a marker object is freed, all of the marker visuals attached to it are also freed and the specific buffer of the object no longer adjusts the marker data when edits occur.) */ ManagedObjectType_Markers = 2, - /* DOC(TODO) */ - ManagedObjectType_Arena = 3, - ManagedObjectType_COUNT = 4, }; -/* DOC(A handle to a managed scope. A managed scope contains variables and objects all of which can be freed and reset in optimized bulk operations. Many managed scopes are created and destroyed by the core to track the lifetime of entities like buffers and views. Because a managed scope contains it's own copy of the managed variables, managed scopes can also be used as a keying mechanism to store and retrieve special information related to entities like buffers and views.) */ + +TYPEDEF u64 Managed_ID; + TYPEDEF u64 Managed_Scope; - -/* DOC(An id refering to a managed variable. Managed variables are created globally, but each managed scope has it's own set of values for the managed variables. Managed variables are created via a unique string. Attempting to create a variable with the same name as an existing variable fails. When naming variables it is recommended that you place a 'module name' followed by a '.' and then a descriptive variable name to distinguish your variables from variables written by other 4coder users that might someday need to work together in the same configuration. Example: "MyUniqueCustomization.variable_name"). The variable's id is used to set and get the value from managed scopes. */ -TYPEDEF i32 Managed_Variable_ID; - -/* DOC(A handle to a managed object. Managed objects have various behaviors and special uses depending on their type. All managed objects share the property of being tied to a managed scope, so that they are cleaned up and freed when that scope's contents are cleared or when the scope is destroyed, they all support store and load operations, although not all with the exact same meanings and implications, and they can all be freed individually instead of with the entire scope.) */ TYPEDEF u64 Managed_Object; static Managed_Scope ManagedScope_NULL = 0; -static Managed_Variable_ID ManagedVariableIndex_ERROR = -1; static Managed_Object ManagedObject_NULL = 0; -/* DOC(A multi-member identifier for a marker visual. A marker visual is attached to a marker object (Marker_Object), it is freed when the marker object is freed or when it is specifically destroyed. Multiple marker visuals can be placed on a single marker object.) -DOC_SEE(Marker_Visual_Type) -DOC_SEE(Marker_Visual_Symbolic_Color) -DOC_SEE(Marker_Visual_Text_Style) -DOC_SEE(Marker_Visual_Take_Rule) -DOC_SEE(Marker_Visual_Priority_Level) -*/ +static Managed_ID ManagedIndex_ERROR = 0; + STRUCT Marker_Visual{ Managed_Scope scope; u32 slot_id; u32 gen_id; }; -/* -DOC(The enumeration of visual effects that a marker visual can create. All effects have a color aspect and text_color aspect. The exact meaning of these aspects depends upon the effect's type. - -There are several effect styles, two effect styles never conflict with one another, each style can be applied to each character. If two effects of the same style are applied to the same character, then the effect with the higher priority is rendered, and the lower priority effect is ignored. The render order for effects is: - -Highlight Style - -Wire Frame Style - -I-Bar Style - -Some effects are character oriented, meaning they have an effect on the individual character/characters that the markers specify. Other effects are line oriented, meaning that they effect the entire line on which their markers are placed. Line oriented highlight style effects are always overriden by character oriented highlight style effects of the same style, regardless of relative priority levels. - -Single marked effects use each marker to specify a single point at which an effect is applied. Range marked effects take pairs of markers to specify a left inclusive right eclusive range to effect. - -In range marked effects, two conflicting effects with the same priority level are further resolved by prefering the effect with the higher-index starting position. This means that if range A completely contains range B and they have the same priority level, then range B will be visible, and range A will be visible wherever range B is not. -) -*/ -ENUM(i32, Marker_Visual_Type) -{ - /* DOC(No visual effect, with this type it is as if the marker visual does not exist.) */ - VisualType_Invisible = 0, - /* DOC(Shows a block around the background of each marked character. The color aspect determines the color of the block behind the characters, the text_color aspect determines the color of the characters. - -This is a character oriented highlight style single marked effect.) */ - VisualType_CharacterBlocks = 1, - /* DOC(Shows a rectangle outline around each marked character. The color aspect determines the color of the rectangle, the text_color aspect is ignored. - -This is a character oriented wire frame style single marked effect.) */ - VisualType_CharacterWireFrames = 2, - /* DOC(Shows a single pixel line on the left side of each marked character. The color aspect determines the color of the line, the text_color aspect is ignored. - -This is a character oriented wire frame style single marked effect.) */ - VisualType_CharacterIBars = 3, - /* DOC(Shows a block in the background of the entire line on which the marker is placed. The color aspect determines the color of the highlight, the text_color aspect is ignored. - -This is a line oriented highlight style single marked effect.) */ - VisualType_LineHighlights = 4, - /* DOC(Shows a block around the background of each character between the range pairs. The color aspect determines the color of the highlight, the text_color aspect is ignored. - -This is a character oriented highlight style range marked effect.) */ - VisualType_CharacterHighlightRanges = 5, - /* DOC(Shows a block in the background of the entire line on each line within the range. The color aspect determines the color of the highlight, the text_color aspect is ignored. - -This is a line oriented highlight style range marked effect.) */ - VisualType_LineHighlightRanges = 6, - VisualType_COUNT = 7, -}; - -/* DOC(Special codes that can be used as the color aspects of marker visual effects. These special codes are for convenience and in some cases effects that could not be expressed as 32-bit colors.) */ -ENUM(u32, Marker_Visual_Symbolic_Color) -{ - /* DOC(When default is used for text_color aspect, the text is unchanged from the coloring the core would apply to it. For all effects, the default value of the color aspect for all effects is the same as transparent. For convenience it is guaranteed this will always be the zero value, so that users may simply pass 0 to color aspects they do not wish to set.) */ - SymbolicColor_Default = 0, - /* DOC(This flag bit-ored with a style tag will be reevaluated at render time to the color of the specific tag in the currently active palette. The macro SymbolicColorFromPalette(Stag_CODE) applies the bit-or to Stag_CODE. For example SymbolicColorFromPalette(Stag_Cursor) will always evaluate to the color of the current cursor. Note that this evaluation happens at render time, so that if the palette changes, the evaluated color will also change.) */ - SymbolicColor__StagColorFlag = 0x00800000, -}; - -/* DOC(Not implemented, but reserved for future use. Where this type is used in the API the value passed should always be zero for now.) */ -ENUM(i32, Marker_Visual_Text_Style) -{ - MARKER_TEXT_STYLE_NOT_YET_IMPLEMENTED, -}; - -/* DOC(The take rule of a marker visual specifies how to iterate the markers in the marker object when applying the visual effect. For range marked effects, which use a pair of markers to specify a left inclusive right exclusive range, it is not necessary that two markers be adjacent in the marker object when they are taken. The first taken marker is paired to the second taken marker, the third to the fourth, etc, regardless of any gaps between the consecutively taken markers. If the take rule overflows the marker object, the effect is still applied, but the iteration is cut short as soon as it would overflow.) */ -STRUCT Marker_Visual_Take_Rule{ - /* DOC(The index of the first marker to take. Indices are zero based. The default value is zero.) */ - i32 first_index; - /* DOC(From the start of a "step" take_count_per_step markers. Markers taken in the same step have consectuive indices. For example, if the first marker taken has index = 0, and the take_count_per_step = 2, then the second marker taken will have index = 1. The default value is 1.) */ - i32 take_count_per_step; - /* DOC(The stride between each "step". After taking take_count_per_step markers from the current step, the iteation advances to the next step counting from the start of current step. So if 2 markers are taken per step, and the stride is 3, then the pattern of taken markers will be **.**.**.**. where * is a tken marker. The core automatically adjusts this field to be at least equal to take_count_per_step before using it to iterate. The default value is 1.) */ - i32 step_stride_in_marker_count; - /* DOC(The maximum number of markers to be taken durring iteration. Since overflow does not cause the visual effect to fail, and is prevented internally, this field can be set to the max value of a signed 32-bit integer and will take as many markers as possible until it hits the end of the marker object. If the maximum count is reached mid-step, the iteration stops without completeing the step.) */ - i32 maximum_number_of_markers; -}; - -/* DOC(A helper enumeration for common priority levels. Although any unsigned integer is a valid priority level, the following five levels are used to establish a standard convention. Highest priority is given to effects immediately at the cursor, mark, and highlighted range. Default priority is given to actively attached effects like compilation error highlights. Passive effects like scope highlighting go to Lowest priority. - -This system is considered a temporary measure and will eventually be replaced with a priority level brokering system to enable cooperation between modules [note made 4.0.29].) */ -ENUM(u32, Marker_Visual_Priority_Level){ - VisualPriority_Lowest = 0, - VisualPriority_Low = 1000, - VisualPriority_Default = 2000, - VisualPriority_High = 3000, - VisualPriority_Highest = 4000, -}; - -/* DOC(Flags that control how font glyphs are modified before drawing.) */ ENUM(u32, Glyph_Flag){ GlyphFlag_None = 0x0, GlyphFlag_Rotate90 = 0x1, }; -/* DOC(Query_Bar is a struct used to store information in the user's control that will be displayed as a drop down bar durring an interactive command.) */ STRUCT Query_Bar{ - /* DOC(This specifies the prompt portion of the drop down bar.) */ String_Const_u8 prompt; - /* DOC(This specifies the main string portion of the drop down bar.) */ String_Const_u8 string; - /* DOC(This specifies the memory capacity allocated for string.) */ umem string_capacity; }; @@ -698,58 +387,30 @@ STRUCT Query_Bar_Ptr_Array{ TYPEDEF_FUNC void UI_Quit_Function_Type(struct Application_Links *app, View_ID view); #define UI_QUIT_FUNCTION(name) void name(struct Application_Links *app, View_ID view) -/* -DOC(Theme_Color stores a style tag/color pair, for the purpose of setting and getting colors in the theme.) -DOC_SEE(Style_Tag) -DOC_SEE(int_color) -*/ STRUCT Theme_Color{ - /* DOC(The style slot in the style palette.) */ id_color tag; - /* DOC(The color in the slot.) */ argb_color color; }; -/* -DOC(Theme lists every color that makes up a standard color scheme.) -DOC_SEE(int_color) -*/ //STRUCT Theme{ -/* DOC(The colors array. Every style tag, beginning with "Stag", is an index into it's corresponding color in the array.) */ //int_color colors[Stag_COUNT]; //}; -/* -DOC(Every face is assigned a unique and consistent Face_ID for it's life time. This represents a slot in which a face can exist. The face in the slot is always valid once it exists, but the face might be changed or released durring it's lifetime. A Face_ID value of zero is reserved for the meaning "not a valid face".) -*/ TYPEDEF u32 Face_ID; -// TODO(allen): redocument STRUCT Font_Load_Location{ String_Const_u8 file_name; b32 in_4coder_font_folder; }; - -// TODO(allen): redocument STRUCT Face_Load_Parameters{ - /* DOC(Indicates the size for the face. Valid values must be greater than 0. Different fonts with the same pt_size do not necessarily have the same line height.) */ u32 pt_size; - - /* DOC(Indicates whether the face tries to use a bold style.) */ b32 bold; - - /* DOC(Indicates whether the face tries to use an italic style.) */ b32 italic; - - /* DOC(Indicates whether the face tries to underline text.) */ b32 underline; - - /* DOC(Indicates whether the face tries to apply hinting.) */ b32 hinting; }; -// TODO(allen): redocument STRUCT Face_Description{ Font_Load_Location font; Face_Load_Parameters parameters; @@ -809,7 +470,6 @@ STRUCT Record_Info{ }; }; -/* DOC(Custom_Command_Function is a function type which matches the signature used for commands. To declare a command use CUSTOM_COMMAND_SIG.) DOC_SEE(CUSTOM_COMMAND_SIG) */ TYPEDEF void Custom_Command_Function(struct Application_Links *app); #if defined(CUSTOM_COMMAND_SIG) || defined(CUSTOM_DOC) || defined(CUSTOM_ALIAS) @@ -826,27 +486,14 @@ TYPEDEF void Custom_Command_Function(struct Application_Links *app); #define CUSTOM_ALIAS(x) CUSTOM_ALIAS(x) #endif -/* DOC(Generic_Command acts as a name for a command, and can name an internal command or a custom command.) */ UNION Generic_Command{ - /* DOC(If this Generic_Command does not represent an internal command the command field is the pointer to the custom command..) */ Custom_Command_Function *command; }; -/* -DOC(User_Input describes an event, such as key presses, mouse button presses, mouse moves, -and also non-input related events like animation frames, and view activation changes.) -DOC_SEE(Generic_Command) -DOC_SEE(Key_Event_Data) -*/ STRUCT User_Input{ - /* DOC(The description of the event.) */ Key_Event_Data key; - /* DOC(If this event would trigger a command, this field specifies what the command would be.) */ Generic_Command command; - /* DOC(This field indicates that an abort event has occurred and the command needs to shut down. -This can be set even if key and command are also set, in which case the command still needs to abort, and the key and command simply reflect -what event triggered the abort event.) */ b32 abort; }; @@ -858,52 +505,30 @@ STRUCT Frame_Info{ TYPEDEF_FUNC void Render_Callback(struct Application_Links *app); -/* DOC(Hook_IDs name the various hooks in 4coder, these hooks use the Hook_Function signature.) -DOC_SEE(Hook_Function) */ ENUM(i32, Hook_ID){ - /* DOC(TODO) */ hook_file_out_of_sync, - /* DOC(TODO) */ hook_exit, - /* DOC(TODO) */ hook_buffer_viewer_update, // never below this hook_type_count }; -/* DOC(Special_Hook_IDs name special hooks that use specialized signatures.) */ ENUM(i32, Special_Hook_ID){ - /* DOC(TODO) */ special_hook_scroll_rule = hook_type_count, - /* DOC(TODO) */ special_hook_new_file, - /* DOC(TODO) */ special_hook_open_file, - /* DOC(TODO) */ special_hook_save_file, - /* DOC(TODO) */ special_hook_end_file, - /* DOC(TODO) */ special_hook_file_edit_range, - /* DOC(TODO) */ special_hook_file_edit_finished, - /* DOC(TODO) */ special_hook_file_externally_modified, - /* DOC(TODO) */ special_hook_command_caller, - /* DOC(TODO) */ special_hook_render_caller, - /* DOC(TODO) */ special_hook_input_filter, - /* DOC(TODO) */ special_hook_start, - /* DOC(TODO) */ special_hook_buffer_name_resolver, - /* DOC(TODO) */ special_hook_modify_color_table, - /* DOC(TODO) */ special_hook_clipboard_change, - /* DOC(TODO) */ special_hook_get_view_buffer_region, }; @@ -916,8 +541,8 @@ TYPEDEF_FUNC void Render_Caller_Function(struct Application_Links *app, Frame_In TYPEDEF_FUNC i32 Hook_Function(struct Application_Links *app); #define HOOK_SIG(name) i32 name(struct Application_Links *app) -TYPEDEF_FUNC i32 Open_File_Hook_Function(struct Application_Links *app, Buffer_ID buffer_id); -#define OPEN_FILE_HOOK_SIG(name) i32 name(struct Application_Links *app, Buffer_ID buffer_id) +TYPEDEF_FUNC i32 Buffer_Hook_Function(struct Application_Links *app, Buffer_ID buffer_id); +#define BUFFER_HOOK_SIG(name) i32 name(struct Application_Links *app, Buffer_ID buffer_id) TYPEDEF_FUNC i32 File_Edit_Range_Function(struct Application_Links *app, Buffer_ID buffer_id, Interval_i64 range, String_Const_u8 text); @@ -975,10 +600,7 @@ TYPEDEF_FUNC i32 Get_Binding_Data_Function(void *data, i32 size); // NOTE(allen): Definitions for the format that Get_Binding_Data uses to launch 4coder. // TODO(allen): Transition to a more dynamic Command_Map system. -/* -DOC(Values for the type field in the discriminated union Binding_Unit.) -DOC_SEE(Binding_Unit) -*/ + ENUM(i32, Binding_Unit_Type){ unit_header, unit_map_begin, @@ -987,7 +609,6 @@ ENUM(i32, Binding_Unit_Type){ unit_hook }; -/* DOC(Values for built in command maps.) */ ENUM(i32, Map_ID){ mapid_global = (1 << 24), mapid_file, @@ -996,8 +617,6 @@ ENUM(i32, Map_ID){ }; -/* -DOC(Describes a unit of information for setting up key bindings. A unit can set a key binding, switch the active map, set the inherited map, or set a hook.) */ STRUCT Binding_Unit{ Binding_Unit_Type type; UNION{ @@ -1045,5 +664,43 @@ STRUCT Process_State{ i64 return_code; }; +ENUM(i16, Token_Base_Kind){ + TokenBaseKind_EOF, + TokenBaseKind_Whitespace, + TokenBaseKind_LexError, + TokenBaseKind_Comment, + TokenBaseKind_Keyword, + TokenBaseKind_Identifier, + TokenBaseKind_Operator, + TokenBaseKind_LiteralInteger, + TokenBaseKind_LiteralFloat, + TokenBaseKind_LiteralString, + TokenBaseKind_ScopeOpen, + TokenBaseKind_ScopeClose, + TokenBaseKind_ParentheticalOpen, + TokenBaseKind_ParentheticalClose, + + TokenBaseKind_COUNT, +}; + +ENUM(u16, Token_Base_Flags){ + TokenBaseFlag_PreProcessorBody = 1, +}; + +STRUCT Token{ + i64 pos; + i64 size; + Token_Base_Kind kind; + Token_Base_Flags flags; + i16 sub_kind; + u16 sub_flags; +}; + +STRUCT Token_Array{ + Token *tokens; + i64 count; + i64 max; +}; + #endif diff --git a/4coder_auto_indent.cpp b/4coder_auto_indent.cpp index 269e31c4..39734612 100644 --- a/4coder_auto_indent.cpp +++ b/4coder_auto_indent.cpp @@ -63,20 +63,20 @@ set_line_indents(Application_Links *app, Arena *arena, Buffer_ID buffer, i64 fir } } -internal Cpp_Token* -seek_matching_token_backwards(Cpp_Token_Array tokens, Cpp_Token *token, - Cpp_Token_Type open_type, Cpp_Token_Type close_type){ +internal Token* +seek_matching_token_backwards(Token_Array tokens, Token *token, + Token_Base_Kind open, Token_Base_Kind close){ if (token <= tokens.tokens){ token = tokens.tokens; } else{ i32 nesting_level = 0; for (; token > tokens.tokens; --token){ - if (!(token->flags & CPP_TFLAG_PP_BODY)){ - if (token->type == close_type){ + if (!HasFlag(token->flags, TokenBaseFlag_PreProcessorBody)){ + if (token->kind == close){ ++nesting_level; } - else if (token->type == open_type){ + else if (token->kind == open){ if (nesting_level == 0){ break; } @@ -91,17 +91,17 @@ seek_matching_token_backwards(Cpp_Token_Array tokens, Cpp_Token *token, } internal Indent_Anchor_Position -find_anchor_token(Application_Links *app, Buffer_ID buffer, Cpp_Token_Array tokens, i64 line_start, i32 tab_width){ +find_anchor_token(Application_Links *app, Buffer_ID buffer, Token_Array tokens, i64 line_start, i32 tab_width){ Indent_Anchor_Position anchor = {}; if (tokens.count > 0){ - Cpp_Token *first_invalid_token = get_first_token_from_line(app, buffer, tokens, line_start); + Token *first_invalid_token = get_first_token_from_line(app, buffer, tokens, line_start); if (first_invalid_token <= tokens.tokens){ anchor.token = tokens.tokens; } else{ i32 stack[256]; i32 top = -1; - Cpp_Token *token_it = tokens.tokens; + Token *token_it = tokens.tokens; i64 highest_checked_line_number = -1; for (; token_it < first_invalid_token; ++token_it){ i64 line_number = get_line_number_from_pos(app, buffer, token_it->start); @@ -169,7 +169,7 @@ find_anchor_token(Application_Links *app, Buffer_ID buffer, Cpp_Token_Array toke internal i64* get_indentation_marks(Application_Links *app, Arena *arena, Buffer_ID buffer, - Cpp_Token_Array tokens, i64 first_line, i64 one_past_last_line, + Token_Array tokens, i64 first_line, i64 one_past_last_line, b32 exact_align, i32 tab_width){ i64 indent_mark_count = one_past_last_line - first_line; i64 *indent_marks = push_array(arena, i64, indent_mark_count); @@ -178,7 +178,7 @@ get_indentation_marks(Application_Links *app, Arena *arena, Buffer_ID buffer, // Decide where to start indentation parsing. Indent_Anchor_Position anchor = find_anchor_token(app, buffer, tokens, first_line, tab_width); - Cpp_Token *token_ptr = anchor.token; + Token *token_ptr = anchor.token; Indent_Parse_State indent = {}; indent.current_indent = anchor.indentation; @@ -199,8 +199,8 @@ get_indentation_marks(Application_Links *app, Arena *arena, Buffer_ID buffer, i64 next_line_start_pos = get_line_start_pos(app, buffer, line_number); indent.previous_line_indent = indent.current_indent; - Cpp_Token prev_token = {}; - Cpp_Token token = {}; + Token prev_token = {}; + Token token = {}; if (token_ptr < tokens.tokens + tokens.count){ token = *token_ptr; } @@ -295,8 +295,8 @@ get_indentation_marks(Application_Links *app, Arena *arena, Buffer_ID buffer, if (indent.current_indent > 0){ b32 statement_complete = false; - Cpp_Token *prev_usable_token_ptr = token_ptr - 1; - Cpp_Token prev_usable_token = {}; + Token *prev_usable_token_ptr = token_ptr - 1; + Token prev_usable_token = {}; if (prev_usable_token_ptr >= tokens.tokens){ prev_usable_token = *prev_usable_token_ptr; } @@ -441,13 +441,13 @@ get_indent_lines_minimum(Application_Links *app, Buffer_ID buffer, i64 start_pos } internal void -get_indent_lines_whole_tokens(Application_Links *app, Buffer_ID buffer, Cpp_Token_Array tokens, i64 start_pos, i64 end_pos, i64 *line_start_out, i64 *line_end_out){ +get_indent_lines_whole_tokens(Application_Links *app, Buffer_ID buffer, Token_Array tokens, i64 start_pos, i64 end_pos, i64 *line_start_out, i64 *line_end_out){ i64 line_start = get_line_number_from_pos(app, buffer, start_pos); i64 line_end = get_line_number_from_pos(app, buffer, end_pos); for (;line_start > 1;){ i64 line_start_pos = get_line_start_pos(app, buffer, line_start); - Cpp_Token *token = get_first_token_from_pos(tokens, line_start_pos); + Token *token = get_first_token_from_pos(tokens, line_start_pos); if (token != 0 && token->start < line_start_pos){ line_start = get_line_number_from_pos(app, buffer, token->start); } @@ -460,7 +460,7 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_ID buffer, Cpp_Toke for (;line_end < line_count;){ i64 next_line_start_pos = get_line_start_pos(app, buffer, line_end + 1); - Cpp_Token *token = get_first_token_from_pos(tokens, next_line_start_pos); + Token *token = get_first_token_from_pos(tokens, next_line_start_pos); if (token != 0 && token->start < next_line_start_pos){ line_end = get_line_number_from_pos(app, buffer, token->start + token->size); } @@ -479,16 +479,14 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_ID buffer, Cpp_Toke internal b32 buffer_auto_indent(Application_Links *app, Buffer_ID buffer, i64 start, i64 end, i32 tab_width, Auto_Indent_Flag flags){ b32 result = false; - if (buffer_exists(app, buffer) && buffer_tokens_are_ready(app, buffer)){ - result = true; - + + Managed_Scope scope = buffer_get_managed_scope(app, buffer); + + Token_Array *tokens_ptr = scope_attachment(app, scope, attachment_tokens, Token_Array); + if (tokens_ptr != 0 && tokens_ptr->count != 0){ Scratch_Block scratch(app); + Token_Array tokens = *token_ptr; - // Stage 1: Read the tokens to be used for indentation. - Cpp_Token_Array tokens = buffer_get_token_array(app, buffer); - - // Stage 2: Decide where the first and last lines are. - // The lines in the range [line_start,line_end) will be indented. i64 line_start = 0; i64 line_end = 0; if (HasFlag(flags, AutoIndent_FullTokens)){ @@ -498,18 +496,16 @@ buffer_auto_indent(Application_Links *app, Buffer_ID buffer, i64 start, i64 end, get_indent_lines_minimum(app, buffer, start, end, &line_start, &line_end); } - // Stage 3: Decide Indent Amounts - // Get an array representing how much each line in - // the range [line_start,line_end) should be indented. i64 *indent_marks = get_indentation_marks(app, scratch, buffer, tokens, line_start, line_end, (flags & AutoIndent_ExactAlignBlock), tab_width); - // Stage 4: Set the Line Indents Indent_Options opts = {}; opts.empty_blank_lines = (flags & AutoIndent_ClearLine); opts.use_tabs = (flags & AutoIndent_UseTab); opts.tab_width = tab_width; set_line_indents(app, scratch, buffer, line_start, line_end, indent_marks, opts); + + result = true; } return(result); diff --git a/4coder_auto_indent.h b/4coder_auto_indent.h index 5b563347..b1b99ac8 100644 --- a/4coder_auto_indent.h +++ b/4coder_auto_indent.h @@ -23,7 +23,7 @@ struct Indent_Parse_State{ }; struct Indent_Anchor_Position{ - Cpp_Token *token; + Token *token; i32 indentation; }; diff --git a/4coder_base_commands.cpp b/4coder_base_commands.cpp index 7ce3f990..8cf15168 100644 --- a/4coder_base_commands.cpp +++ b/4coder_base_commands.cpp @@ -695,11 +695,14 @@ CUSTOM_DOC("Toggles the visibility status of the current view's filebar.") CUSTOM_COMMAND_SIG(toggle_line_wrap) CUSTOM_DOC("Toggles the current buffer's line wrapping status.") { + NotImplemented; +#if 0 View_ID view = get_active_view(app, AccessProtected); Buffer_ID buffer = view_get_buffer(app, view, AccessProtected); b32 wrapped; buffer_get_setting(app, buffer, BufferSetting_WrapLine, &wrapped); buffer_set_setting(app, buffer, BufferSetting_WrapLine, !wrapped); +#endif } CUSTOM_COMMAND_SIG(toggle_fps_meter) @@ -711,21 +714,27 @@ CUSTOM_DOC("Toggles the visibility of the FPS performance meter") CUSTOM_COMMAND_SIG(increase_line_wrap) CUSTOM_DOC("Increases the current buffer's width for line wrapping.") { + NotImplemented; +#if 0 View_ID view = get_active_view(app, AccessProtected); Buffer_ID buffer = view_get_buffer(app, view, AccessProtected); i32 wrap = 0; buffer_get_setting(app, buffer, BufferSetting_WrapPosition, &wrap); buffer_set_setting(app, buffer, BufferSetting_WrapPosition, wrap + 10); +#endif } CUSTOM_COMMAND_SIG(decrease_line_wrap) CUSTOM_DOC("Decrases the current buffer's width for line wrapping.") { + NotImplemented; +#if 0 View_ID view = get_active_view(app, AccessProtected); Buffer_ID buffer = view_get_buffer(app, view, AccessProtected); i32 wrap = 0; buffer_get_setting(app, buffer, BufferSetting_WrapPosition, &wrap); buffer_set_setting(app, buffer, BufferSetting_WrapPosition, wrap - 10); +#endif } CUSTOM_COMMAND_SIG(increase_face_size) diff --git a/4coder_base_types.cpp b/4coder_base_types.cpp index 004e626f..cd861988 100644 --- a/4coder_base_types.cpp +++ b/4coder_base_types.cpp @@ -9,154 +9,154 @@ #define C_MATH 1 -static i32 +internal i32 ceil32(f32 v){ return(((v)>0)?( (v == (i32)(v))?((i32)(v)):((i32)((v)+1.f)) ):( ((i32)(v)) )); } -static i32 +internal i32 floor32(f32 v){ return(((v)<0)?( (v == (i32)(v))?((i32)(v)):((i32)((v)-1.f)) ):( ((i32)(v)) )); } -static i32 +internal i32 round32(f32 v){ return(floor32(v + 0.5f)); } -static f32 +internal f32 f32_ceil32(f32 v){ return((f32)ceil32(v)); } -static f32 +internal f32 f32_floor32(f32 v){ return((f32)floor32(v)); } -static f32 +internal f32 f32_round32(f32 v){ return((f32)round32(v)); } -static i8 +internal i8 round_up_i8(i8 x, i8 b){ x += b - 1; x -= x%b; return(x); } -static u8 +internal u8 round_up_u8(u8 x, u8 b){ x += b - 1; x -= x%b; return(x); } -static i16 +internal i16 round_up_i16(i16 x, i16 b){ x += b - 1; x -= x%b; return(x); } -static u16 +internal u16 round_up_u16(u16 x, u16 b){ x += b - 1; x -= x%b; return(x); } -static i32 +internal i32 round_up_i32(i32 x, i32 b){ x += b - 1; x -= x%b; return(x); } -static u32 +internal u32 round_up_u32(u32 x, u32 b){ x += b - 1; x -= x%b; return(x); } -static i64 +internal i64 round_up_i64(i64 x, i64 b){ x += b - 1; x -= x%b; return(x); } -static u64 +internal u64 round_up_u64(u64 x, u64 b){ x += b - 1; x -= x%b; return(x); } -static imem +internal imem round_up_imem(imem x, imem b){ x += b - 1; x -= x%b; return(x); } -static umem +internal umem round_up_umem(umem x, umem b){ x += b - 1; x -= x%b; return(x); } -static i8 +internal i8 round_down_i8(i8 x, i8 b){ x -= x%b; return(x); } -static u8 +internal u8 round_down_u8(u8 x, u8 b){ x -= x%b; return(x); } -static i16 +internal i16 round_down_i16(i16 x, i16 b){ x -= x%b; return(x); } -static u16 +internal u16 round_down_u16(u16 x, u16 b){ x -= x%b; return(x); } -static i32 +internal i32 round_down_i32(i32 x, i32 b){ x -= x%b; return(x); } -static u32 +internal u32 round_down_u32(u32 x, u32 b){ x -= x%b; return(x); } -static i64 +internal i64 round_down_i64(i64 x, i64 b){ x -= x%b; return(x); } -static u64 +internal u64 round_down_u64(u64 x, u64 b){ x -= x%b; return(x); } -static imem +internal imem round_down_imem(imem x, imem b){ x -= x%b; return(x); } -static umem +internal umem round_down_umem(umem x, umem b){ x -= x%b; return(x); } -static f32 +internal f32 f32_integer(f32 x){ return((f32)((i32)x)); } -static u32 +internal u32 round_up_pot_u32(u32 x){ --x; x |= x >> 1; @@ -170,7 +170,7 @@ round_up_pot_u32(u32 x){ //////////////////////////////// -static Data +internal Data make_data(void *memory, umem size){ Data data = {(u8*)memory, size}; return(data); @@ -187,19 +187,27 @@ global_const Data zero_data = {}; //////////////////////////////// -static void +internal void block_zero(void *mem, umem size){ for (u8 *p = (u8*)mem, *e = p + size; p < e; p += 1){ *p = 0; } } -static void +internal void +block_zero(Data data){ + block_zero(data.data, data.size); +} +internal void block_fill_ones(void *mem, umem size){ for (u8 *p = (u8*)mem, *e = p + size; p < e; p += 1){ *p = 0xFF; } } -static void +internal void +block_fill_ones(Data data){ + block_fill_ones(data.data, data.size); +} +internal void block_copy(void *dst, void *src, umem size){ u8 *d = (u8*)dst; u8 *s = (u8*)src; @@ -218,7 +226,7 @@ block_copy(void *dst, void *src, umem size){ } } } -static b32 +internal b32 block_match(void *a, void *b, umem size){ b32 result = true; for (u8 *pa = (u8*)a, *pb = (u8*)b, *ea = pa + size; pa < ea; pa += 1, pb += 1){ @@ -229,7 +237,7 @@ block_match(void *a, void *b, umem size){ } return(result); } -static i32 +internal i32 block_compare(void *a, void *b, umem size){ i32 result = 0; for (u8 *pa = (u8*)a, *pb = (u8*)b, *ea = pa + size; pa < ea; pa += 1, pb += 1){ @@ -241,13 +249,13 @@ block_compare(void *a, void *b, umem size){ } return(result); } -static void +internal void block_fill_u8(void *a, umem size, u8 val){ for (u8 *ptr = (u8*)a, *e = ptr + size; ptr < e; ptr += 1){ *ptr = val; } } -static void +internal void block_fill_u16(void *a, umem size, u16 val){ Assert(size%sizeof(u16) == 0); umem count = size/sizeof(u16); @@ -255,7 +263,7 @@ block_fill_u16(void *a, umem size, u16 val){ *ptr = val; } } -static void +internal void block_fill_u32(void *a, umem size, u32 val){ Assert(size%sizeof(u32) == 0); umem count = size/sizeof(u32); @@ -263,7 +271,7 @@ block_fill_u32(void *a, umem size, u32 val){ *ptr = val; } } -static void +internal void block_fill_u64(void *a, umem size, u64 val){ Assert(size%sizeof(u64) == 0); umem count = size/sizeof(u64); @@ -285,7 +293,7 @@ block_fill_u64(void *a, umem size, u64 val){ //////////////////////////////// -static f32 +internal f32 abs_f32(f32 x){ if (x < 0){ x = -x; @@ -296,7 +304,7 @@ abs_f32(f32 x){ #if C_MATH #include -static f32 +internal f32 mod_f32(f32 x, i32 m){ f32 whole; f32 frac = modff(x, &whole); @@ -307,256 +315,256 @@ mod_f32(f32 x, i32 m){ //////////////////////////////// -static Vec2_i8 +internal Vec2_i8 V2i8(i8 x, i8 y){ Vec2_i8 v = {x, y}; return(v); } -static Vec3_i8 +internal Vec3_i8 V3i8(i8 x, i8 y, i8 z){ Vec3_i8 v = {x, y, z}; return(v); } -static Vec4_i8 +internal Vec4_i8 V4i8(i8 x, i8 y, i8 z, i8 w){ Vec4_i8 v = {x, y, z, w}; return(v); } -static Vec2_i16 +internal Vec2_i16 V2i16(i16 x, i16 y){ Vec2_i16 v = {x, y}; return(v); } -static Vec3_i16 +internal Vec3_i16 V3i16(i16 x, i16 y, i16 z){ Vec3_i16 v = {x, y, z}; return(v); } -static Vec4_i16 +internal Vec4_i16 V4i16(i16 x, i16 y, i16 z, i16 w){ Vec4_i16 v = {x, y, z, w}; return(v); } -static Vec2_i32 +internal Vec2_i32 V2i32(i32 x, i32 y){ Vec2_i32 v = {x, y}; return(v); } -static Vec3_i32 +internal Vec3_i32 V3i32(i32 x, i32 y, i32 z){ Vec3_i32 v = {x, y, z}; return(v); } -static Vec4_i32 +internal Vec4_i32 V4i32(i32 x, i32 y, i32 z, i32 w){ Vec4_i32 v = {x, y, z, w}; return(v); } -static Vec2_f32 +internal Vec2_f32 V2f32(f32 x, f32 y){ Vec2_f32 v = {x, y}; return(v); } -static Vec3_f32 +internal Vec3_f32 V3f32(f32 x, f32 y, f32 z){ Vec3_f32 v = {x, y, z}; return(v); } -static Vec4_f32 +internal Vec4_f32 V4f32(f32 x, f32 y, f32 z, f32 w){ Vec4_f32 v = {x, y, z, w}; return(v); } -static Vec2_i8 +internal Vec2_i8 V2i8(Vec2_i8 o){ return(V2i8((i8)o.x, (i8)o.y)); } -static Vec2_i8 +internal Vec2_i8 V2i8(Vec2_i16 o){ return(V2i8((i8)o.x, (i8)o.y)); } -static Vec2_i8 +internal Vec2_i8 V2i8(Vec2_i32 o){ return(V2i8((i8)o.x, (i8)o.y)); } -static Vec2_i8 +internal Vec2_i8 V2i8(Vec2_f32 o){ return(V2i8((i8)o.x, (i8)o.y)); } -static Vec3_i8 +internal Vec3_i8 V3i8(Vec3_i8 o){ return(V3i8((i8)o.x, (i8)o.y, (i8)o.z)); } -static Vec3_i8 +internal Vec3_i8 V3i8(Vec3_i16 o){ return(V3i8((i8)o.x, (i8)o.y, (i8)o.z)); } -static Vec3_i8 +internal Vec3_i8 V3i8(Vec3_i32 o){ return(V3i8((i8)o.x, (i8)o.y, (i8)o.z)); } -static Vec3_i8 +internal Vec3_i8 V3i8(Vec3_f32 o){ return(V3i8((i8)o.x, (i8)o.y, (i8)o.z)); } -static Vec4_i8 +internal Vec4_i8 V4i8(Vec4_i8 o){ return(V4i8((i8)o.x, (i8)o.y, (i8)o.z, (i8)o.w)); } -static Vec4_i8 +internal Vec4_i8 V4i8(Vec4_i16 o){ return(V4i8((i8)o.x, (i8)o.y, (i8)o.z, (i8)o.w)); } -static Vec4_i8 +internal Vec4_i8 V4i8(Vec4_i32 o){ return(V4i8((i8)o.x, (i8)o.y, (i8)o.z, (i8)o.w)); } -static Vec4_i8 +internal Vec4_i8 V4i8(Vec4_f32 o){ return(V4i8((i8)o.x, (i8)o.y, (i8)o.z, (i8)o.w)); } -static Vec2_i16 +internal Vec2_i16 V2i16(Vec2_i8 o){ return(V2i16((i16)o.x, (i16)o.y)); } -static Vec2_i16 +internal Vec2_i16 V2i16(Vec2_i16 o){ return(V2i16((i16)o.x, (i16)o.y)); } -static Vec2_i16 +internal Vec2_i16 V2i16(Vec2_i32 o){ return(V2i16((i16)o.x, (i16)o.y)); } -static Vec2_i16 +internal Vec2_i16 V2i16(Vec2_f32 o){ return(V2i16((i16)o.x, (i16)o.y)); } -static Vec3_i16 +internal Vec3_i16 V3i16(Vec3_i8 o){ return(V3i16((i16)o.x, (i16)o.y, (i16)o.z)); } -static Vec3_i16 +internal Vec3_i16 V3i16(Vec3_i16 o){ return(V3i16((i16)o.x, (i16)o.y, (i16)o.z)); } -static Vec3_i16 +internal Vec3_i16 V3i16(Vec3_i32 o){ return(V3i16((i16)o.x, (i16)o.y, (i16)o.z)); } -static Vec3_i16 +internal Vec3_i16 V3i16(Vec3_f32 o){ return(V3i16((i16)o.x, (i16)o.y, (i16)o.z)); } -static Vec4_i16 +internal Vec4_i16 V4i16(Vec4_i8 o){ return(V4i16((i16)o.x, (i16)o.y, (i16)o.z, (i16)o.w)); } -static Vec4_i16 +internal Vec4_i16 V4i16(Vec4_i16 o){ return(V4i16((i16)o.x, (i16)o.y, (i16)o.z, (i16)o.w)); } -static Vec4_i16 +internal Vec4_i16 V4i16(Vec4_i32 o){ return(V4i16((i16)o.x, (i16)o.y, (i16)o.z, (i16)o.w)); } -static Vec4_i16 +internal Vec4_i16 V4i16(Vec4_f32 o){ return(V4i16((i16)o.x, (i16)o.y, (i16)o.z, (i16)o.w)); } -static Vec2_i32 +internal Vec2_i32 V2i32(Vec2_i8 o){ return(V2i32((i32)o.x, (i32)o.y)); } -static Vec2_i32 +internal Vec2_i32 V2i32(Vec2_i16 o){ return(V2i32((i32)o.x, (i32)o.y)); } -static Vec2_i32 +internal Vec2_i32 V2i32(Vec2_i32 o){ return(V2i32((i32)o.x, (i32)o.y)); } -static Vec2_i32 +internal Vec2_i32 V2i32(Vec2_f32 o){ return(V2i32((i32)o.x, (i32)o.y)); } -static Vec3_i32 +internal Vec3_i32 V3i32(Vec3_i8 o){ return(V3i32((i32)o.x, (i32)o.y, (i32)o.z)); } -static Vec3_i32 +internal Vec3_i32 V3i32(Vec3_i16 o){ return(V3i32((i32)o.x, (i32)o.y, (i32)o.z)); } -static Vec3_i32 +internal Vec3_i32 V3i32(Vec3_i32 o){ return(V3i32((i32)o.x, (i32)o.y, (i32)o.z)); } -static Vec3_i32 +internal Vec3_i32 V3i32(Vec3_f32 o){ return(V3i32((i32)o.x, (i32)o.y, (i32)o.z)); } -static Vec4_i32 +internal Vec4_i32 V4i32(Vec4_i8 o){ return(V4i32((i32)o.x, (i32)o.y, (i32)o.z, (i32)o.w)); } -static Vec4_i32 +internal Vec4_i32 V4i32(Vec4_i16 o){ return(V4i32((i32)o.x, (i32)o.y, (i32)o.z, (i32)o.w)); } -static Vec4_i32 +internal Vec4_i32 V4i32(Vec4_i32 o){ return(V4i32((i32)o.x, (i32)o.y, (i32)o.z, (i32)o.w)); } -static Vec4_i32 +internal Vec4_i32 V4i32(Vec4_f32 o){ return(V4i32((i32)o.x, (i32)o.y, (i32)o.z, (i32)o.w)); } -static Vec2_f32 +internal Vec2_f32 V2f32(Vec2_i8 o){ return(V2f32((f32)o.x, (f32)o.y)); } -static Vec2_f32 +internal Vec2_f32 V2f32(Vec2_i16 o){ return(V2f32((f32)o.x, (f32)o.y)); } -static Vec2_f32 +internal Vec2_f32 V2f32(Vec2_i32 o){ return(V2f32((f32)o.x, (f32)o.y)); } -static Vec2_f32 +internal Vec2_f32 V2f32(Vec2_f32 o){ return(V2f32((f32)o.x, (f32)o.y)); } -static Vec3_f32 +internal Vec3_f32 V3f32(Vec3_i8 o){ return(V3f32((f32)o.x, (f32)o.y, (f32)o.z)); } -static Vec3_f32 +internal Vec3_f32 V3f32(Vec3_i16 o){ return(V3f32((f32)o.x, (f32)o.y, (f32)o.z)); } -static Vec3_f32 +internal Vec3_f32 V3f32(Vec3_i32 o){ return(V3f32((f32)o.x, (f32)o.y, (f32)o.z)); } -static Vec3_f32 +internal Vec3_f32 V3f32(Vec3_f32 o){ return(V3f32((f32)o.x, (f32)o.y, (f32)o.z)); } -static Vec4_f32 +internal Vec4_f32 V4f32(Vec4_i8 o){ return(V4f32((f32)o.x, (f32)o.y, (f32)o.z, (f32)o.w)); } -static Vec4_f32 +internal Vec4_f32 V4f32(Vec4_i16 o){ return(V4f32((f32)o.x, (f32)o.y, (f32)o.z, (f32)o.w)); } -static Vec4_f32 +internal Vec4_f32 V4f32(Vec4_i32 o){ return(V4f32((f32)o.x, (f32)o.y, (f32)o.z, (f32)o.w)); } -static Vec4_f32 +internal Vec4_f32 V4f32(Vec4_f32 o){ return(V4f32((f32)o.x, (f32)o.y, (f32)o.z, (f32)o.w)); } @@ -565,20 +573,20 @@ V4f32(Vec4_f32 o){ #define V3 V3f32 #define V4 V4f32 -static Vec2_i8 +internal Vec2_i8 operator+(Vec2_i8 a, Vec2_i8 b){ a.x += b.x; a.y += b.y; return(a); } -static Vec3_i8 +internal Vec3_i8 operator+(Vec3_i8 a, Vec3_i8 b){ a.x += b.x; a.y += b.y; a.z += b.z; return(a); } -static Vec4_i8 +internal Vec4_i8 operator+(Vec4_i8 a, Vec4_i8 b){ a.x += b.x; a.y += b.y; @@ -586,20 +594,20 @@ operator+(Vec4_i8 a, Vec4_i8 b){ a.w += b.w; return(a); } -static Vec2_i16 +internal Vec2_i16 operator+(Vec2_i16 a, Vec2_i16 b){ a.x += b.x; a.y += b.y; return(a); } -static Vec3_i16 +internal Vec3_i16 operator+(Vec3_i16 a, Vec3_i16 b){ a.x += b.x; a.y += b.y; a.z += b.z; return(a); } -static Vec4_i16 +internal Vec4_i16 operator+(Vec4_i16 a, Vec4_i16 b){ a.x += b.x; a.y += b.y; @@ -607,20 +615,20 @@ operator+(Vec4_i16 a, Vec4_i16 b){ a.w += b.w; return(a); } -static Vec2_i32 +internal Vec2_i32 operator+(Vec2_i32 a, Vec2_i32 b){ a.x += b.x; a.y += b.y; return(a); } -static Vec3_i32 +internal Vec3_i32 operator+(Vec3_i32 a, Vec3_i32 b){ a.x += b.x; a.y += b.y; a.z += b.z; return(a); } -static Vec4_i32 +internal Vec4_i32 operator+(Vec4_i32 a, Vec4_i32 b){ a.x += b.x; a.y += b.y; @@ -628,20 +636,20 @@ operator+(Vec4_i32 a, Vec4_i32 b){ a.w += b.w; return(a); } -static Vec2_f32 +internal Vec2_f32 operator+(Vec2_f32 a, Vec2_f32 b){ a.x += b.x; a.y += b.y; return(a); } -static Vec3_f32 +internal Vec3_f32 operator+(Vec3_f32 a, Vec3_f32 b){ a.x += b.x; a.y += b.y; a.z += b.z; return(a); } -static Vec4_f32 +internal Vec4_f32 operator+(Vec4_f32 a, Vec4_f32 b){ a.x += b.x; a.y += b.y; @@ -650,20 +658,20 @@ operator+(Vec4_f32 a, Vec4_f32 b){ return(a); } -static Vec2_i8& +internal Vec2_i8& operator+=(Vec2_i8 &a, Vec2_i8 b){ a.x += b.x; a.y += b.y; return(a); } -static Vec3_i8& +internal Vec3_i8& operator+=(Vec3_i8 &a, Vec3_i8 b){ a.x += b.x; a.y += b.y; a.z += b.z; return(a); } -static Vec4_i8& +internal Vec4_i8& operator+=(Vec4_i8 &a, Vec4_i8 b){ a.x += b.x; a.y += b.y; @@ -671,20 +679,20 @@ operator+=(Vec4_i8 &a, Vec4_i8 b){ a.w += b.w; return(a); } -static Vec2_i16& +internal Vec2_i16& operator+=(Vec2_i16 &a, Vec2_i16 b){ a.x += b.x; a.y += b.y; return(a); } -static Vec3_i16& +internal Vec3_i16& operator+=(Vec3_i16 &a, Vec3_i16 b){ a.x += b.x; a.y += b.y; a.z += b.z; return(a); } -static Vec4_i16& +internal Vec4_i16& operator+=(Vec4_i16 &a, Vec4_i16 b){ a.x += b.x; a.y += b.y; @@ -692,20 +700,20 @@ operator+=(Vec4_i16 &a, Vec4_i16 b){ a.w += b.w; return(a); } -static Vec2_i32& +internal Vec2_i32& operator+=(Vec2_i32 &a, Vec2_i32 b){ a.x += b.x; a.y += b.y; return(a); } -static Vec3_i32& +internal Vec3_i32& operator+=(Vec3_i32 &a, Vec3_i32 b){ a.x += b.x; a.y += b.y; a.z += b.z; return(a); } -static Vec4_i32& +internal Vec4_i32& operator+=(Vec4_i32 &a, Vec4_i32 b){ a.x += b.x; a.y += b.y; @@ -713,20 +721,20 @@ operator+=(Vec4_i32 &a, Vec4_i32 b){ a.w += b.w; return(a); } -static Vec2_f32& +internal Vec2_f32& operator+=(Vec2_f32 &a, Vec2_f32 b){ a.x += b.x; a.y += b.y; return(a); } -static Vec3_f32& +internal Vec3_f32& operator+=(Vec3_f32 &a, Vec3_f32 b){ a.x += b.x; a.y += b.y; a.z += b.z; return(a); } -static Vec4_f32& +internal Vec4_f32& operator+=(Vec4_f32 &a, Vec4_f32 b){ a.x += b.x; a.y += b.y; @@ -735,20 +743,20 @@ operator+=(Vec4_f32 &a, Vec4_f32 b){ return(a); } -static Vec2_i8 +internal Vec2_i8 operator-(Vec2_i8 a, Vec2_i8 b){ a.x -= b.x; a.y -= b.y; return(a); } -static Vec3_i8 +internal Vec3_i8 operator-(Vec3_i8 a, Vec3_i8 b){ a.x -= b.x; a.y -= b.y; a.z -= b.z; return(a); } -static Vec4_i8 +internal Vec4_i8 operator-(Vec4_i8 a, Vec4_i8 b){ a.x -= b.x; a.y -= b.y; @@ -756,20 +764,20 @@ operator-(Vec4_i8 a, Vec4_i8 b){ a.w -= b.w; return(a); } -static Vec2_i16 +internal Vec2_i16 operator-(Vec2_i16 a, Vec2_i16 b){ a.x -= b.x; a.y -= b.y; return(a); } -static Vec3_i16 +internal Vec3_i16 operator-(Vec3_i16 a, Vec3_i16 b){ a.x -= b.x; a.y -= b.y; a.z -= b.z; return(a); } -static Vec4_i16 +internal Vec4_i16 operator-(Vec4_i16 a, Vec4_i16 b){ a.x -= b.x; a.y -= b.y; @@ -777,20 +785,20 @@ operator-(Vec4_i16 a, Vec4_i16 b){ a.w -= b.w; return(a); } -static Vec2_i32 +internal Vec2_i32 operator-(Vec2_i32 a, Vec2_i32 b){ a.x -= b.x; a.y -= b.y; return(a); } -static Vec3_i32 +internal Vec3_i32 operator-(Vec3_i32 a, Vec3_i32 b){ a.x -= b.x; a.y -= b.y; a.z -= b.z; return(a); } -static Vec4_i32 +internal Vec4_i32 operator-(Vec4_i32 a, Vec4_i32 b){ a.x -= b.x; a.y -= b.y; @@ -798,20 +806,20 @@ operator-(Vec4_i32 a, Vec4_i32 b){ a.w -= b.w; return(a); } -static Vec2_f32 +internal Vec2_f32 operator-(Vec2_f32 a, Vec2_f32 b){ a.x -= b.x; a.y -= b.y; return(a); } -static Vec3_f32 +internal Vec3_f32 operator-(Vec3_f32 a, Vec3_f32 b){ a.x -= b.x; a.y -= b.y; a.z -= b.z; return(a); } -static Vec4_f32 +internal Vec4_f32 operator-(Vec4_f32 a, Vec4_f32 b){ a.x -= b.x; a.y -= b.y; @@ -820,20 +828,20 @@ operator-(Vec4_f32 a, Vec4_f32 b){ return(a); } -static Vec2_i8& +internal Vec2_i8& operator-=(Vec2_i8 &a, Vec2_i8 b){ a.x -= b.x; a.y -= b.y; return(a); } -static Vec3_i8& +internal Vec3_i8& operator-=(Vec3_i8 &a, Vec3_i8 b){ a.x -= b.x; a.y -= b.y; a.z -= b.z; return(a); } -static Vec4_i8& +internal Vec4_i8& operator-=(Vec4_i8 &a, Vec4_i8 b){ a.x -= b.x; a.y -= b.y; @@ -841,20 +849,20 @@ operator-=(Vec4_i8 &a, Vec4_i8 b){ a.w -= b.w; return(a); } -static Vec2_i16& +internal Vec2_i16& operator-=(Vec2_i16 &a, Vec2_i16 b){ a.x -= b.x; a.y -= b.y; return(a); } -static Vec3_i16& +internal Vec3_i16& operator-=(Vec3_i16 &a, Vec3_i16 b){ a.x -= b.x; a.y -= b.y; a.z -= b.z; return(a); } -static Vec4_i16& +internal Vec4_i16& operator-=(Vec4_i16 &a, Vec4_i16 b){ a.x -= b.x; a.y -= b.y; @@ -862,20 +870,20 @@ operator-=(Vec4_i16 &a, Vec4_i16 b){ a.w -= b.w; return(a); } -static Vec2_i32& +internal Vec2_i32& operator-=(Vec2_i32 &a, Vec2_i32 b){ a.x -= b.x; a.y -= b.y; return(a); } -static Vec3_i32& +internal Vec3_i32& operator-=(Vec3_i32 &a, Vec3_i32 b){ a.x -= b.x; a.y -= b.y; a.z -= b.z; return(a); } -static Vec4_i32& +internal Vec4_i32& operator-=(Vec4_i32 &a, Vec4_i32 b){ a.x -= b.x; a.y -= b.y; @@ -883,20 +891,20 @@ operator-=(Vec4_i32 &a, Vec4_i32 b){ a.w -= b.w; return(a); } -static Vec2_f32& +internal Vec2_f32& operator-=(Vec2_f32 &a, Vec2_f32 b){ a.x -= b.x; a.y -= b.y; return(a); } -static Vec3_f32& +internal Vec3_f32& operator-=(Vec3_f32 &a, Vec3_f32 b){ a.x -= b.x; a.y -= b.y; a.z -= b.z; return(a); } -static Vec4_f32& +internal Vec4_f32& operator-=(Vec4_f32 &a, Vec4_f32 b){ a.x -= b.x; a.y -= b.y; @@ -905,33 +913,33 @@ operator-=(Vec4_f32 &a, Vec4_f32 b){ return(a); } -static Vec2_i8 +internal Vec2_i8 operator*(i8 s, Vec2_i8 v){ v.x *= s; v.y *= s; return(v); } -static Vec2_i8 +internal Vec2_i8 operator*(Vec2_i8 v, i8 s){ v.x *= s; v.y *= s; return(v); } -static Vec3_i8 +internal Vec3_i8 operator*(i8 s, Vec3_i8 v){ v.x *= s; v.y *= s; v.z *= s; return(v); } -static Vec3_i8 +internal Vec3_i8 operator*(Vec3_i8 v, i8 s){ v.x *= s; v.y *= s; v.z *= s; return(v); } -static Vec4_i8 +internal Vec4_i8 operator*(i8 s, Vec4_i8 v){ v.x *= s; v.y *= s; @@ -939,7 +947,7 @@ operator*(i8 s, Vec4_i8 v){ v.w *= s; return(v); } -static Vec4_i8 +internal Vec4_i8 operator*(Vec4_i8 v, i8 s){ v.x *= s; v.y *= s; @@ -947,33 +955,33 @@ operator*(Vec4_i8 v, i8 s){ v.w *= s; return(v); } -static Vec2_i16 +internal Vec2_i16 operator*(i16 s, Vec2_i16 v){ v.x *= s; v.y *= s; return(v); } -static Vec2_i16 +internal Vec2_i16 operator*(Vec2_i16 v, i16 s){ v.x *= s; v.y *= s; return(v); } -static Vec3_i16 +internal Vec3_i16 operator*(i16 s, Vec3_i16 v){ v.x *= s; v.y *= s; v.z *= s; return(v); } -static Vec3_i16 +internal Vec3_i16 operator*(Vec3_i16 v, i16 s){ v.x *= s; v.y *= s; v.z *= s; return(v); } -static Vec4_i16 +internal Vec4_i16 operator*(i16 s, Vec4_i16 v){ v.x *= s; v.y *= s; @@ -981,7 +989,7 @@ operator*(i16 s, Vec4_i16 v){ v.w *= s; return(v); } -static Vec4_i16 +internal Vec4_i16 operator*(Vec4_i16 v, i16 s){ v.x *= s; v.y *= s; @@ -989,33 +997,33 @@ operator*(Vec4_i16 v, i16 s){ v.w *= s; return(v); } -static Vec2_i32 +internal Vec2_i32 operator*(i32 s, Vec2_i32 v){ v.x *= s; v.y *= s; return(v); } -static Vec2_i32 +internal Vec2_i32 operator*(Vec2_i32 v, i32 s){ v.x *= s; v.y *= s; return(v); } -static Vec3_i32 +internal Vec3_i32 operator*(i32 s, Vec3_i32 v){ v.x *= s; v.y *= s; v.z *= s; return(v); } -static Vec3_i32 +internal Vec3_i32 operator*(Vec3_i32 v, i32 s){ v.x *= s; v.y *= s; v.z *= s; return(v); } -static Vec4_i32 +internal Vec4_i32 operator*(i32 s, Vec4_i32 v){ v.x *= s; v.y *= s; @@ -1023,7 +1031,7 @@ operator*(i32 s, Vec4_i32 v){ v.w *= s; return(v); } -static Vec4_i32 +internal Vec4_i32 operator*(Vec4_i32 v, i32 s){ v.x *= s; v.y *= s; @@ -1031,33 +1039,33 @@ operator*(Vec4_i32 v, i32 s){ v.w *= s; return(v); } -static Vec2_f32 +internal Vec2_f32 operator*(f32 s, Vec2_f32 v){ v.x *= s; v.y *= s; return(v); } -static Vec2_f32 +internal Vec2_f32 operator*(Vec2_f32 v, f32 s){ v.x *= s; v.y *= s; return(v); } -static Vec3_f32 +internal Vec3_f32 operator*(f32 s, Vec3_f32 v){ v.x *= s; v.y *= s; v.z *= s; return(v); } -static Vec3_f32 +internal Vec3_f32 operator*(Vec3_f32 v, f32 s){ v.x *= s; v.y *= s; v.z *= s; return(v); } -static Vec4_f32 +internal Vec4_f32 operator*(f32 s, Vec4_f32 v){ v.x *= s; v.y *= s; @@ -1065,7 +1073,7 @@ operator*(f32 s, Vec4_f32 v){ v.w *= s; return(v); } -static Vec4_f32 +internal Vec4_f32 operator*(Vec4_f32 v, f32 s){ v.x *= s; v.y *= s; @@ -1074,20 +1082,20 @@ operator*(Vec4_f32 v, f32 s){ return(v); } -static Vec2_i8& +internal Vec2_i8& operator*=(Vec2_i8 &v, i8 s){ v.x *= s; v.y *= s; return(v); } -static Vec3_i8& +internal Vec3_i8& operator*=(Vec3_i8 &v, i8 s){ v.x *= s; v.y *= s; v.z *= s; return(v); } -static Vec4_i8& +internal Vec4_i8& operator*=(Vec4_i8 &v, i8 s){ v.x *= s; v.y *= s; @@ -1095,20 +1103,20 @@ operator*=(Vec4_i8 &v, i8 s){ v.w *= s; return(v); } -static Vec2_i16& +internal Vec2_i16& operator*=(Vec2_i16 &v, i16 s){ v.x *= s; v.y *= s; return(v); } -static Vec3_i16& +internal Vec3_i16& operator*=(Vec3_i16 &v, i16 s){ v.x *= s; v.y *= s; v.z *= s; return(v); } -static Vec4_i16& +internal Vec4_i16& operator*=(Vec4_i16 &v, i16 s){ v.x *= s; v.y *= s; @@ -1116,20 +1124,20 @@ operator*=(Vec4_i16 &v, i16 s){ v.w *= s; return(v); } -static Vec2_i32& +internal Vec2_i32& operator*=(Vec2_i32 &v, i32 s){ v.x *= s; v.y *= s; return(v); } -static Vec3_i32& +internal Vec3_i32& operator*=(Vec3_i32 &v, i32 s){ v.x *= s; v.y *= s; v.z *= s; return(v); } -static Vec4_i32& +internal Vec4_i32& operator*=(Vec4_i32 &v, i32 s){ v.x *= s; v.y *= s; @@ -1137,20 +1145,20 @@ operator*=(Vec4_i32 &v, i32 s){ v.w *= s; return(v); } -static Vec2_f32& +internal Vec2_f32& operator*=(Vec2_f32 &v, f32 s){ v.x *= s; v.y *= s; return(v); } -static Vec3_f32& +internal Vec3_f32& operator*=(Vec3_f32 &v, f32 s){ v.x *= s; v.y *= s; v.z *= s; return(v); } -static Vec4_f32& +internal Vec4_f32& operator*=(Vec4_f32 &v, f32 s){ v.x *= s; v.y *= s; @@ -1159,20 +1167,20 @@ operator*=(Vec4_f32 &v, f32 s){ return(v); } -static Vec2_i8 +internal Vec2_i8 operator/(Vec2_i8 v, i8 s){ v.x /= s; v.y /= s; return(v); } -static Vec3_i8 +internal Vec3_i8 operator/(Vec3_i8 v, i8 s){ v.x /= s; v.y /= s; v.z /= s; return(v); } -static Vec4_i8 +internal Vec4_i8 operator/(Vec4_i8 v, i8 s){ v.x /= s; v.y /= s; @@ -1180,20 +1188,20 @@ operator/(Vec4_i8 v, i8 s){ v.w /= s; return(v); } -static Vec2_i16 +internal Vec2_i16 operator/(Vec2_i16 v, i16 s){ v.x /= s; v.y /= s; return(v); } -static Vec3_i16 +internal Vec3_i16 operator/(Vec3_i16 v, i16 s){ v.x /= s; v.y /= s; v.z /= s; return(v); } -static Vec4_i16 +internal Vec4_i16 operator/(Vec4_i16 v, i16 s){ v.x /= s; v.y /= s; @@ -1201,20 +1209,20 @@ operator/(Vec4_i16 v, i16 s){ v.w /= s; return(v); } -static Vec2_i32 +internal Vec2_i32 operator/(Vec2_i32 v, i32 s){ v.x /= s; v.y /= s; return(v); } -static Vec3_i32 +internal Vec3_i32 operator/(Vec3_i32 v, i32 s){ v.x /= s; v.y /= s; v.z /= s; return(v); } -static Vec4_i32 +internal Vec4_i32 operator/(Vec4_i32 v, i32 s){ v.x /= s; v.y /= s; @@ -1222,20 +1230,20 @@ operator/(Vec4_i32 v, i32 s){ v.w /= s; return(v); } -static Vec2_f32 +internal Vec2_f32 operator/(Vec2_f32 v, f32 s){ v.x /= s; v.y /= s; return(v); } -static Vec3_f32 +internal Vec3_f32 operator/(Vec3_f32 v, f32 s){ v.x /= s; v.y /= s; v.z /= s; return(v); } -static Vec4_f32 +internal Vec4_f32 operator/(Vec4_f32 v, f32 s){ v.x /= s; v.y /= s; @@ -1244,20 +1252,20 @@ operator/(Vec4_f32 v, f32 s){ return(v); } -static Vec2_i8& +internal Vec2_i8& operator/=(Vec2_i8 &v, i8 s){ v.x /= s; v.y /= s; return(v); } -static Vec3_i8& +internal Vec3_i8& operator/=(Vec3_i8 &v, i8 s){ v.x /= s; v.y /= s; v.z /= s; return(v); } -static Vec4_i8& +internal Vec4_i8& operator/=(Vec4_i8 &v, i8 s){ v.x /= s; v.y /= s; @@ -1265,20 +1273,20 @@ operator/=(Vec4_i8 &v, i8 s){ v.w /= s; return(v); } -static Vec2_i16& +internal Vec2_i16& operator/=(Vec2_i16 &v, i16 s){ v.x /= s; v.y /= s; return(v); } -static Vec3_i16& +internal Vec3_i16& operator/=(Vec3_i16 &v, i16 s){ v.x /= s; v.y /= s; v.z /= s; return(v); } -static Vec4_i16& +internal Vec4_i16& operator/=(Vec4_i16 &v, i16 s){ v.x /= s; v.y /= s; @@ -1286,20 +1294,20 @@ operator/=(Vec4_i16 &v, i16 s){ v.w /= s; return(v); } -static Vec2_i32& +internal Vec2_i32& operator/=(Vec2_i32 &v, i32 s){ v.x /= s; v.y /= s; return(v); } -static Vec3_i32& +internal Vec3_i32& operator/=(Vec3_i32 &v, i32 s){ v.x /= s; v.y /= s; v.z /= s; return(v); } -static Vec4_i32& +internal Vec4_i32& operator/=(Vec4_i32 &v, i32 s){ v.x /= s; v.y /= s; @@ -1307,20 +1315,20 @@ operator/=(Vec4_i32 &v, i32 s){ v.w /= s; return(v); } -static Vec2_f32& +internal Vec2_f32& operator/=(Vec2_f32 &v, f32 s){ v.x /= s; v.y /= s; return(v); } -static Vec3_f32& +internal Vec3_f32& operator/=(Vec3_f32 &v, f32 s){ v.x /= s; v.y /= s; v.z /= s; return(v); } -static Vec4_f32& +internal Vec4_f32& operator/=(Vec4_f32 &v, f32 s){ v.x /= s; v.y /= s; @@ -1329,122 +1337,122 @@ operator/=(Vec4_f32 &v, f32 s){ return(v); } -static b32 +internal b32 operator==(Vec2_i8 a, Vec2_i8 b){ return(a.x == b.x && a.y == b.y); } -static b32 +internal b32 operator==(Vec3_i8 a, Vec3_i8 b){ return(a.x == b.x && a.y == b.y && a.z == b.z); } -static b32 +internal b32 operator==(Vec4_i8 a, Vec4_i8 b){ return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w); } -static b32 +internal b32 operator==(Vec2_i16 a, Vec2_i16 b){ return(a.x == b.x && a.y == b.y); } -static b32 +internal b32 operator==(Vec3_i16 a, Vec3_i16 b){ return(a.x == b.x && a.y == b.y && a.z == b.z); } -static b32 +internal b32 operator==(Vec4_i16 a, Vec4_i16 b){ return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w); } -static b32 +internal b32 operator==(Vec2_i32 a, Vec2_i32 b){ return(a.x == b.x && a.y == b.y); } -static b32 +internal b32 operator==(Vec3_i32 a, Vec3_i32 b){ return(a.x == b.x && a.y == b.y && a.z == b.z); } -static b32 +internal b32 operator==(Vec4_i32 a, Vec4_i32 b){ return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w); } -static b32 +internal b32 operator==(Vec2_f32 a, Vec2_f32 b){ return(a.x == b.x && a.y == b.y); } -static b32 +internal b32 operator==(Vec3_f32 a, Vec3_f32 b){ return(a.x == b.x && a.y == b.y && a.z == b.z); } -static b32 +internal b32 operator==(Vec4_f32 a, Vec4_f32 b){ return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w); } -static b32 +internal b32 operator!=(Vec2_i8 a, Vec2_i8 b){ return(a.x != b.x || a.y != b.y); } -static b32 +internal b32 operator!=(Vec3_i8 a, Vec3_i8 b){ return(a.x != b.x || a.y != b.y || a.z != b.z); } -static b32 +internal b32 operator!=(Vec4_i8 a, Vec4_i8 b){ return(a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w); } -static b32 +internal b32 operator!=(Vec2_i16 a, Vec2_i16 b){ return(a.x != b.x || a.y != b.y); } -static b32 +internal b32 operator!=(Vec3_i16 a, Vec3_i16 b){ return(a.x != b.x || a.y != b.y || a.z != b.z); } -static b32 +internal b32 operator!=(Vec4_i16 a, Vec4_i16 b){ return(a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w); } -static b32 +internal b32 operator!=(Vec2_i32 a, Vec2_i32 b){ return(a.x != b.x || a.y != b.y); } -static b32 +internal b32 operator!=(Vec3_i32 a, Vec3_i32 b){ return(a.x != b.x || a.y != b.y || a.z != b.z); } -static b32 +internal b32 operator!=(Vec4_i32 a, Vec4_i32 b){ return(a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w); } -static b32 +internal b32 operator!=(Vec2_f32 a, Vec2_f32 b){ return(a.x != b.x || a.y != b.y); } -static b32 +internal b32 operator!=(Vec3_f32 a, Vec3_f32 b){ return(a.x != b.x || a.y != b.y || a.z != b.z); } -static b32 +internal b32 operator!=(Vec4_f32 a, Vec4_f32 b){ return(a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w); } //////////////////////////////// -static b32 +internal b32 near_zero(f32 p, f32 epsilon){ return(-epsilon <= p && p <= epsilon); } -static b32 +internal b32 near_zero(Vec2_f32 p, f32 epsilon){ return(-epsilon <= p.x && p.x <= epsilon && -epsilon <= p.y && p.y <= epsilon); } -static b32 +internal b32 near_zero(Vec3_f32 p, f32 epsilon){ return(-epsilon <= p.x && p.x <= epsilon && -epsilon <= p.y && p.y <= epsilon && -epsilon <= p.z && p.z <= epsilon); } -static b32 +internal b32 near_zero(Vec4_f32 p, f32 epsilon){ return(-epsilon <= p.x && p.x <= epsilon && -epsilon <= p.y && p.y <= epsilon && @@ -1452,63 +1460,63 @@ near_zero(Vec4_f32 p, f32 epsilon){ -epsilon <= p.w && p.w <= epsilon); } -static b32 +internal b32 near_zero(f32 p){ return(near_zero(p, epsilon_f32)); } -static b32 +internal b32 near_zero(Vec2_f32 p){ return(near_zero(p, epsilon_f32)); } -static b32 +internal b32 near_zero(Vec3_f32 p){ return(near_zero(p, epsilon_f32)); } -static b32 +internal b32 near_zero(Vec4_f32 p){ return(near_zero(p, epsilon_f32)); } //////////////////////////////// -static b32 +internal b32 operator==(Rect_i32 a, Rect_i32 b){ return(a.p0 == b.p0 && a.p1 == b.p1); } -static b32 +internal b32 operator==(Rect_f32 a, Rect_f32 b){ return(a.p0 == b.p0 && a.p1 == b.p1); } -static b32 +internal b32 operator!=(Rect_i32 a, Rect_i32 b){ return(!(a == b)); } -static b32 +internal b32 operator!=(Rect_f32 a, Rect_f32 b){ return(!(a == b)); } //////////////////////////////// -static f32 +internal f32 lerp(f32 a, f32 t, f32 b){ return(a + (b-a)*t); } -static i32 +internal i32 lerp(i32 a, f32 t, i32 b){ return((i32)(lerp((f32)a, t, (f32)b))); } -static Vec2 +internal Vec2 lerp(Vec2 a, f32 t, Vec2 b){ return(a + (b-a)*t); } -static Vec3 +internal Vec3 lerp(Vec3 a, f32 t, Vec3 b){ return(a + (b-a)*t); } -static Vec4 +internal Vec4 lerp(Vec4 a, f32 t, Vec4 b){ return(a + (b-a)*t); } -static f32 +internal f32 unlerp(f32 a, f32 x, f32 b){ f32 r = x; if (b != a){ @@ -1520,7 +1528,7 @@ unlerp(f32 a, f32 x, f32 b){ //////////////////////////////// // TODO(allen): Convert colors to Vec4 -static u32 +internal u32 color_blend(u32 a, f32 t, u32 b){ union{ u8 byte[4]; @@ -1535,7 +1543,7 @@ color_blend(u32 a, f32 t, u32 b){ return(R.comp); } -static Vec3 +internal Vec3 unpack_color3(u32 color){ Vec3 result; result.r = ((color >> 16) & 0xFF)/255.f; @@ -1544,7 +1552,7 @@ unpack_color3(u32 color){ return(result); } -static Vec4 +internal Vec4 unpack_color4(u32 color){ Vec4 result; result.a = ((color >> 24) & 0xFF)/255.f; @@ -1554,7 +1562,7 @@ unpack_color4(u32 color){ return(result); } -static u32 +internal u32 pack_color4(Vec4 color){ u32 result = ((u8)(color.a*255) << 24) | @@ -1564,7 +1572,7 @@ pack_color4(Vec4 color){ return(result); } -static Vec4 +internal Vec4 rgba_to_hsla(Vec4 rgba){ Vec4 hsla = {}; f32 max, min, delta; @@ -1620,7 +1628,7 @@ rgba_to_hsla(Vec4 rgba){ return(hsla); } -static Vec4 +internal Vec4 hsla_to_rgba(Vec4 hsla){ if (hsla.h >= 1.f){ hsla.h = 0.f; @@ -2253,21 +2261,21 @@ flip_side(Side side){ //////////////////////////////// -static void* +internal void* base_reserve__noop(void *user_data, umem size, umem *size_out){ *size_out = 0; return(0); } -static void +internal void base_commit__noop(void *user_data, void *ptr, umem size){} -static void +internal void base_uncommit__noop(void *user_data, void *ptr, umem size){} -static void +internal void base_free__noop(void *user_data, void *ptr){} -static void +internal void base_set_access__noop(void *user_data, void *ptr, umem size, Access_Flag flags){} -static Base_Allocator +internal Base_Allocator make_base_allocator(Base_Allocator_Reserve_Signature *func_reserve, Base_Allocator_Commit_Signature *func_commit, Base_Allocator_Uncommit_Signature *func_uncommit, @@ -2299,37 +2307,39 @@ make_base_allocator(Base_Allocator_Reserve_Signature *func_reserve, }; return(base_allocator); } -static Data +internal Data base_allocate(Base_Allocator *allocator, umem size){ umem full_size = 0; void *memory = allocator->reserve(allocator->user_data, size, &full_size); allocator->commit(allocator->user_data, memory, full_size); return(make_data(memory, full_size)); } -static void +internal void base_free(Base_Allocator *allocator, void *ptr){ if (ptr != 0){ allocator->free(allocator->user_data, ptr); } } +#define base_array(a,T,c) (T*)(base_allocate((a), sizeof(T)*(c)).data) + //////////////////////////////// -static Cursor +internal Cursor make_cursor(void *base, umem size){ Cursor cursor = {(u8*)base, 0, size}; return(cursor); } -static Cursor +internal Cursor make_cursor(Data data){ return(make_cursor(data.data, data.size)); } -static Cursor +internal Cursor make_cursor(Base_Allocator *allocator, umem size){ Data memory = base_allocate(allocator, size); return(make_cursor(memory)); } -static Data +internal Data linalloc_push(Cursor *cursor, umem size){ Data result = {}; if (cursor->pos + size <= cursor->cap){ @@ -2339,7 +2349,7 @@ linalloc_push(Cursor *cursor, umem size){ } return(result); } -static void +internal void linalloc_pop(Cursor *cursor, umem size){ if (cursor->pos > size){ cursor->pos -= size; @@ -2348,39 +2358,39 @@ linalloc_pop(Cursor *cursor, umem size){ cursor->pos = 0; } } -static Data +internal Data linalloc_align(Cursor *cursor, umem alignment){ umem pos = round_up_umem(cursor->pos, alignment); umem new_size = pos - cursor->pos; return(linalloc_push(cursor, new_size)); } -static Temp_Memory_Cursor +internal Temp_Memory_Cursor linalloc_begin_temp(Cursor *cursor){ Temp_Memory_Cursor temp = {cursor, cursor->pos}; return(temp); } -static void +internal void linalloc_end_temp(Temp_Memory_Cursor temp){ temp.cursor->pos = temp.pos; } -static void +internal void linalloc_clear(Cursor *cursor){ cursor->pos = 0; } -static Arena +internal Arena make_arena(Base_Allocator *allocator, umem chunk_size, umem alignment){ Arena arena = {allocator, 0, chunk_size, alignment}; return(arena); } -static Arena +internal Arena make_arena(Base_Allocator *allocator, umem chunk_size){ return(make_arena(allocator, chunk_size, 8)); } -static Arena +internal Arena make_arena(Base_Allocator *allocator){ return(make_arena(allocator, KB(16), 8)); } -static Cursor_Node* +internal Cursor_Node* arena__new_node(Arena *arena, umem min_size){ min_size = clamp_bot(min_size, arena->chunk_size); Data memory = base_allocate(arena->base_allocator, min_size + sizeof(Cursor_Node)); @@ -2389,7 +2399,7 @@ arena__new_node(Arena *arena, umem min_size){ sll_stack_push(arena->cursor_node, cursor_node); return(cursor_node); } -static Data +internal Data linalloc_push(Arena *arena, umem size){ Data result = {}; if (size > 0){ @@ -2407,7 +2417,7 @@ linalloc_push(Arena *arena, umem size){ } return(result); } -static void +internal void linalloc_pop(Arena *arena, umem size){ Base_Allocator *allocator = arena->base_allocator; Cursor_Node *cursor_node = arena->cursor_node; @@ -2426,7 +2436,7 @@ linalloc_pop(Arena *arena, umem size){ } arena->cursor_node = cursor_node; } -static Data +internal Data linalloc_align(Arena *arena, umem alignment){ arena->alignment = alignment; Data data = {}; @@ -2436,14 +2446,14 @@ linalloc_align(Arena *arena, umem alignment){ } return(data); } -static Temp_Memory_Arena +internal Temp_Memory_Arena linalloc_begin_temp(Arena *arena){ Cursor_Node *cursor_node = arena->cursor_node; Temp_Memory_Arena temp = {arena, cursor_node, cursor_node == 0?0:cursor_node->cursor.pos}; return(temp); } -static void +internal void linalloc_end_temp(Temp_Memory_Arena temp){ Base_Allocator *allocator = temp.arena->base_allocator; Cursor_Node *cursor_node = temp.arena->cursor_node; @@ -2464,12 +2474,12 @@ linalloc_end_temp(Temp_Memory_Arena temp){ } } } -static void +internal void linalloc_clear(Arena *arena){ Temp_Memory_Arena temp = {arena, 0, 0}; linalloc_end_temp(temp); } -static void +internal void arena_tap(Arena *arena){ Cursor_Node *cursor_node = arena->cursor_node; if (cursor_node == 0){ @@ -2479,7 +2489,7 @@ arena_tap(Arena *arena){ arena__new_node(arena, 0); } } -static Cursor* +internal Cursor* arena_as_cursor(Arena *arena){ Cursor *cursor = 0; arena_tap(arena); @@ -2489,16 +2499,16 @@ arena_as_cursor(Arena *arena){ } return(cursor); } -static void* +internal void* linalloc_wrap_unintialized(Data data){ return(data.data); } -static void* +internal void* linalloc_wrap_zero(Data data){ block_zero(data.data, data.size); return(data.data); } -static void* +internal void* linalloc_wrap_write(Data data, umem size, void *src){ block_copy(data.data, src, clamp_top(data.size, size)); return(data.data); @@ -2509,19 +2519,19 @@ linalloc_wrap_write(Data data, umem size, void *src){ #define pop_array(a,T,c) (linalloc_pop((a), sizeof(T)*(c))) #define push_align(a,b) (linalloc_align((a), (b))) #define push_align_zero(a,b) (linalloc_wrap_zero(linalloc_align((a), (b)))) -static Temp_Memory +internal Temp_Memory begin_temp(Cursor *cursor){ Temp_Memory temp = {LinearAllocatorKind_Cursor}; temp.temp_memory_cursor = linalloc_begin_temp(cursor); return(temp); } -static Temp_Memory +internal Temp_Memory begin_temp(Arena *arena){ Temp_Memory temp = {LinearAllocatorKind_Arena}; temp.temp_memory_arena = linalloc_begin_temp(arena); return(temp); } -static void +internal void end_temp(Temp_Memory temp){ switch (temp.kind){ case LinearAllocatorKind_Cursor: @@ -2537,7 +2547,188 @@ end_temp(Temp_Memory temp){ //////////////////////////////// -static Data +#define heap__sent_init(s) (s)->next=(s)->prev=(s) +#define heap__insert_next(p,n) ((n)->next=(p)->next,(n)->prev=(p),(n)->next->prev=(n),(p)->next=(n)) +#define heap__insert_prev(p,n) ((n)->prev=(p)->prev,(n)->next=(p),(n)->prev->next=(n),(p)->prev=(n)) +#define heap__remove(n) ((n)->next->prev=(n)->prev,(n)->prev->next=(n)->next) + +#if defined(DO_HEAP_CHECKS) +internal void +heap_assert_good(Heap *heap){ + if (heap->in_order.next != 0){ + Assert(heap->in_order.prev != 0); + Assert(heap->free_nodes.next != 0); + Assert(heap->free_nodes.prev != 0); + for (Heap_Basic_Node *node = &heap->in_order;;){ + Assert(node->next->prev == node); + Assert(node->prev->next == node); + node = node->next; + if (node == &heap->in_order){ + break; + } + } + for (Heap_Basic_Node *node = &heap->free_nodes;;){ + Assert(node->next->prev == node); + Assert(node->prev->next == node); + node = node->next; + if (node == &heap->free_nodes){ + break; + } + } + } +} +#else +#define heap_assert_good(heap) ((void)(heap)) +#endif + +internal void +heap_init(Heap *heap, Base_Allocator *allocator){ + heap->arena = make_arena(allocator, KB(64), KB(8)); + heap__sent_init(&heap->in_order); + heap__sent_init(&heap->free_nodes); + heap->used_space = 0; + heap->total_space = 0; +} + +internal Base_Allocator* +heap_free_all(Heap *heap){ + Base_Allocator *allocator = heap->arena.base_allocator; + linalloc_clear(&heap->arena); + block_zero_struct(heap); + return(allocator); +} + +internal void +heap__extend(Heap *heap, void *memory, umem size){ + heap_assert_good(heap); + if (size >= sizeof(Heap_Node)){ + Heap_Node *new_node = (Heap_Node*)memory; + heap__insert_prev(&heap->in_order, &new_node->order); + heap__insert_next(&heap->free_nodes, &new_node->alloc); + new_node->size = size - sizeof(*new_node); + heap->total_space += size; + } + heap_assert_good(heap); +} + +internal void +heap__extend_automatic(Heap *heap, umem size){ + void *memory = push_array(&heap->arena, u8, size); + heap__extend(heap, memory, size); +} + +internal void* +heap__reserve_chunk(Heap *heap, Heap_Node *node, umem size){ + u8 *ptr = (u8*)(node + 1); + Assert(node->size >= size); + umem left_over_size = node->size - size; + if (left_over_size > sizeof(*node)){ + umem new_node_size = left_over_size - sizeof(*node); + Heap_Node *new_node = (Heap_Node*)(ptr + size); + heap__insert_next(&node->order, &new_node->order); + heap__insert_next(&node->alloc, &new_node->alloc); + new_node->size = new_node_size; + } + heap__remove(&node->alloc); + node->alloc.next = 0; + node->alloc.prev = 0; + node->size = size; + heap->used_space += sizeof(*node) + size; + return(ptr); +} + +internal void* +heap_allocate(Heap *heap, umem size){ + b32 first_try = true; + for (;;){ + if (heap->in_order.next != 0){ + heap_assert_good(heap); + umem aligned_size = (size + sizeof(Heap_Node) - 1); + aligned_size = aligned_size - (aligned_size%sizeof(Heap_Node)); + for (Heap_Basic_Node *n = heap->free_nodes.next; + n != &heap->free_nodes; + n = n->next){ + Heap_Node *node = CastFromMember(Heap_Node, alloc, n); + if (node->size >= aligned_size){ + void *ptr = heap__reserve_chunk(heap, node, aligned_size); + heap_assert_good(heap); + return(ptr); + } + } + heap_assert_good(heap); + } + + if (first_try){ + umem extension_size = clamp_bot(KB(64), size*2); + heap__extend_automatic(heap, extension_size); + first_try = false; + } + else{ + break; + } + } + return(0); +} + +internal void +heap__merge(Heap *heap, Heap_Node *l, Heap_Node *r){ + if (&l->order != &heap->in_order && &r->order != &heap->in_order && + l->alloc.next != 0 && l->alloc.prev != 0 && + r->alloc.next != 0 && r->alloc.prev != 0){ + u8 *ptr = (u8*)(l + 1) + l->size; + if (PtrDif(ptr, r) == 0){ + heap__remove(&r->order); + heap__remove(&r->alloc); + heap__remove(&l->alloc); + l->size += r->size + sizeof(*r); + heap__insert_next(&heap->free_nodes, &l->alloc); + } + } +} + +internal void +heap_free(Heap *heap, void *memory){ + if (heap->in_order.next != 0 && memory != 0){ + Heap_Node *node = ((Heap_Node*)memory) - 1; + Assert(node->alloc.next == 0); + Assert(node->alloc.prev == 0); + heap->used_space -= sizeof(*node) + node->size; + heap_assert_good(heap); + heap__insert_next(&heap->free_nodes, &node->alloc); + heap_assert_good(heap); + heap__merge(heap, node, CastFromMember(Heap_Node, order, node->order.next)); + heap_assert_good(heap); + heap__merge(heap, CastFromMember(Heap_Node, order, node->order.prev), node); + heap_assert_good(heap); + } +} + +#define heap_array(heap, T, c) (T*)(heap_allocate((heap), sizeof(T)*(c))) + +//////////////////////////////// + +internal void* +base_reserve__heap(void *user_data, umem size, umem *size_out){ + Heap *heap = (Heap*)user_data; + void *memory = heap_allocate(heap, size); + *size_out = size; + return(memory); +} + +internal void +base_free__heap(void *user_data, void *ptr){ + Heap *heap = (Heap*)user_data; + heap_free(heap, ptr); +} + +internal Base_Allocator +base_allocator_on_heap(Heap *heap){ + return(make_base_allocator(base_reserve__heap, 0, 0, base_free__heap, 0, heap)); +} + +//////////////////////////////// + +internal Data push_data(Arena *arena, umem size){ Data result = {}; result.data = push_array(arena, u8, size); @@ -2545,7 +2736,7 @@ push_data(Arena *arena, umem size){ return(result); } -static Data +internal Data push_data_copy(Arena *arena, Data data){ Data result = {}; result.data = push_array_write(arena, u8, data.size, data.data); @@ -2553,127 +2744,127 @@ push_data_copy(Arena *arena, Data data){ return(result); } -static b32 +internal b32 data_match(Data a, Data b){ return(a.size == b.size && block_match(a.data, b.data, a.size)); } //////////////////////////////// -static b32 +internal b32 character_is_slash(char c){ return((c == '/') || (c == '\\')); } -static b32 +internal b32 character_is_slash(u8 c){ return((c == '/') || (c == '\\')); } -static b32 +internal b32 character_is_slash(u16 c){ return((c == '/') || (c == '\\')); } -static b32 +internal b32 character_is_slash(u32 c){ return((c == '/') || (c == '\\')); } -static b32 +internal b32 character_is_upper(char c){ return(('A' <= c) && (c <= 'Z')); } -static b32 +internal b32 character_is_upper(u8 c){ return(('A' <= c) && (c <= 'Z')); } -static b32 +internal b32 character_is_upper(u16 c){ return(('A' <= c) && (c <= 'Z')); } -static b32 +internal b32 character_is_upper(u32 c){ return(('A' <= c) && (c <= 'Z')); } -static b32 +internal b32 character_is_lower(char c){ return(('a' <= c) && (c <= 'z')); } -static b32 +internal b32 character_is_lower(u8 c){ return(('a' <= c) && (c <= 'z')); } -static b32 +internal b32 character_is_lower(u16 c){ return(('a' <= c) && (c <= 'z')); } -static b32 +internal b32 character_is_lower(u32 c){ return(('a' <= c) && (c <= 'z')); } -static b32 +internal b32 character_is_lower_unicode(u8 c){ return((('a' <= c) && (c <= 'z')) || c >= 128); } -static b32 +internal b32 character_is_lower_unicode(u16 c){ return((('a' <= c) && (c <= 'z')) || c >= 128); } -static b32 +internal b32 character_is_lower_unicode(u32 c){ return((('a' <= c) && (c <= 'z')) || c >= 128); } -static char +internal char character_to_upper(char c){ if (('a' <= c) && (c <= 'z')){ c -= 'a' - 'A'; } return(c); } -static u8 +internal u8 character_to_upper(u8 c){ if (('a' <= c) && (c <= 'z')){ c -= 'a' - 'A'; } return(c); } -static u16 +internal u16 character_to_upper(u16 c){ if (('a' <= c) && (c <= 'z')){ c -= 'a' - 'A'; } return(c); } -static u32 +internal u32 character_to_upper(u32 c){ if (('a' <= c) && (c <= 'z')){ c -= 'a' - 'A'; } return(c); } -static char +internal char character_to_lower(char c){ if (('A' <= c) && (c <= 'Z')){ c += 'a' - 'A'; } return(c); } -static u8 +internal u8 character_to_lower(u8 c){ if (('A' <= c) && (c <= 'Z')){ c += 'a' - 'A'; } return(c); } -static u16 +internal u16 character_to_lower(u16 c){ if (('A' <= c) && (c <= 'Z')){ c += 'a' - 'A'; } return(c); } -static u32 +internal u32 character_to_lower(u32 c){ if (('A' <= c) && (c <= 'Z')){ c += 'a' - 'A'; @@ -2681,79 +2872,79 @@ character_to_lower(u32 c){ return(c); } -static b32 +internal b32 character_is_whitespace(char c){ return(c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v'); } -static b32 +internal b32 character_is_whitespace(u8 c){ return(c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v'); } -static b32 +internal b32 character_is_whitespace(u16 c){ return(c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v'); } -static b32 +internal b32 character_is_whitespace(u32 c){ return(c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v'); } -static b32 +internal b32 character_is_base10(char c){ return('0' <= c && c <= '9'); } -static b32 +internal b32 character_is_base10(u8 c){ return('0' <= c && c <= '9'); } -static b32 +internal b32 character_is_base10(u16 c){ return('0' <= c && c <= '9'); } -static b32 +internal b32 character_is_base10(u32 c){ return('0' <= c && c <= '9'); } -static b32 +internal b32 character_is_base16(char c){ return(('0' <= c && c <= '9') || ('A' <= c && c <= 'F')); } -static b32 +internal b32 character_is_base16(u8 c){ return(('0' <= c && c <= '9') || ('A' <= c && c <= 'F')); } -static b32 +internal b32 character_is_base16(u16 c){ return(('0' <= c && c <= '9') || ('A' <= c && c <= 'F')); } -static b32 +internal b32 character_is_base16(u32 c){ return(('0' <= c && c <= '9') || ('A' <= c && c <= 'F')); } -static b32 +internal b32 character_is_base64(char c){ return(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '_' || c == '$' || c == '?'); } -static b32 +internal b32 character_is_base64(u8 c){ return(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '_' || c == '$' || c == '?'); } -static b32 +internal b32 character_is_base64(u16 c){ return(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '_' || c == '$' || c == '?'); } -static b32 +internal b32 character_is_base64(u32 c){ return(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || @@ -2761,114 +2952,114 @@ character_is_base64(u32 c){ c == '_' || c == '$' || c == '?'); } -static b32 +internal b32 character_is_alpha(char c){ return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_'); } -static b32 +internal b32 character_is_alpha(u8 c){ return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_'); } -static b32 +internal b32 character_is_alpha(u16 c){ return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_'); } -static b32 +internal b32 character_is_alpha(u32 c){ return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_'); } -static b32 +internal b32 character_is_alpha_numeric(char c){ return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_'); } -static b32 +internal b32 character_is_alpha_numeric(u8 c){ return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_'); } -static b32 +internal b32 character_is_alpha_numeric(u16 c){ return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_'); } -static b32 +internal b32 character_is_alpha_numeric(u32 c){ return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_'); } -static b32 +internal b32 character_is_alpha_unicode(u8 c){ return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_' || c >= 128); } -static b32 +internal b32 character_is_alpha_unicode(u16 c){ return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_' || c >= 128); } -static b32 +internal b32 character_is_alpha_unicode(u32 c){ return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_' || c >= 128); } -static b32 +internal b32 character_is_alpha_numeric_unicode(u8 c){ return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_' || c >= 128); } -static b32 +internal b32 character_is_alpha_numeric_unicode(u16 c){ return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_' || c >= 128); } -static b32 +internal b32 character_is_alpha_numeric_unicode(u32 c){ return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_' || c >= 128); } -static umem +internal umem cstring_length(char *str){ umem length = 0; for (;str[length] != 0; length += 1); return(length); } -static umem +internal umem cstring_length(u8 *str){ umem length = 0; for (;str[length] != 0; length += 1); return(length); } -static umem +internal umem cstring_length(u16 *str){ umem length = 0; for (;str[length] != 0; length += 1); return(length); } -static umem +internal umem cstring_length(u32 *str){ umem length = 0; for (;str[length] != 0; length += 1); return(length); } -static String_char +internal String_char Schar(char *str, umem size, umem cap){ String_char string = {str, size, cap}; return(string); } -static String_u8 +internal String_u8 Su8(u8 *str, umem size, umem cap){ String_u8 string = {str, size, cap}; return(string); } -static String_u16 +internal String_u16 Su16(u16 *str, umem size, umem cap){ String_u16 string = {str, size, cap}; return(string); } -static String_u32 +internal String_u32 Su32(u32 *str, umem size, umem cap){ String_u32 string = {str, size, cap}; return(string); } -static String_Any +internal String_Any Sany(void *str, umem size, umem cap, String_Encoding encoding){ String_Any string = {encoding}; switch (encoding){ @@ -2880,28 +3071,28 @@ Sany(void *str, umem size, umem cap, String_Encoding encoding){ return(string); } -static String_char +internal String_char Schar(char *str, umem size){ String_char string = {str, size, size + 1}; return(string); } -static String_u8 +internal String_u8 Su8(u8 *str, umem size){ String_u8 string = {str, size, size + 1}; return(string); } -static String_u16 +internal String_u16 Su16(u16 *str, umem size){ String_u16 string = {str, size, size + 1}; return(string); } -static String_u32 +internal String_u32 Su32(u32 *str, umem size){ String_u32 string = {str, size, size + 1}; return(string); } -static String_Any +internal String_Any Sany(void *str, umem size, String_Encoding encoding){ String_Any string = {encoding}; switch (encoding){ @@ -2913,24 +3104,24 @@ Sany(void *str, umem size, String_Encoding encoding){ return(string); } -static String_char +internal String_char Schar(char *str, char *one_past_last){ return(Schar(str, (umem)(one_past_last - str))); } -static String_u8 +internal String_u8 Su8(u8 *str, u8 *one_past_last){ return(Su8(str, (umem)(one_past_last - str))); } -static String_u16 +internal String_u16 Su16(u16 *str, u16 *one_past_last){ return(Su16(str, (umem)(one_past_last - str))); } -static String_u32 +internal String_u32 Su32(u32 *str, u32 *one_past_last){ return(Su32(str, (umem)(one_past_last - str))); } -static String_Any +internal String_Any Sany(void *str, void *one_past_last, String_Encoding encoding){ String_Any string = {encoding}; switch (encoding){ @@ -2942,32 +3133,32 @@ Sany(void *str, void *one_past_last, String_Encoding encoding){ return(string); } -static String_char +internal String_char Schar(char *str){ umem size = cstring_length(str); String_char string = {str, size, size + 1}; return(string); } -static String_u8 +internal String_u8 Su8(u8 *str){ umem size = cstring_length(str); String_u8 string = {str, size, size + 1}; return(string); } -static String_u16 +internal String_u16 Su16(u16 *str){ umem size = cstring_length(str); String_u16 string = {str, size, size + 1}; return(string); } -static String_u32 +internal String_u32 Su32(u32 *str){ umem size = cstring_length(str); String_u32 string = {str, size, size + 1}; return(string); } -static String_Any +internal String_Any Sany(void *str, String_Encoding encoding){ String_Any string = {encoding}; switch (encoding){ @@ -2979,74 +3170,74 @@ Sany(void *str, String_Encoding encoding){ return(string); } -static String_char +internal String_char Schar(String_Const_char str, umem cap){ String_char string = {str.str, str.size, cap}; return(string); } -static String_u8 +internal String_u8 Su8(String_Const_u8 str, umem cap){ String_u8 string = {str.str, str.size, cap}; return(string); } -static String_u16 +internal String_u16 Su16(String_Const_u16 str, umem cap){ String_u16 string = {str.str, str.size, cap}; return(string); } -static String_u32 +internal String_u32 Su32(String_Const_u32 str, umem cap){ String_u32 string = {str.str, str.size, cap}; return(string); } -static String_Any +internal String_Any SCany(String_char str){ String_Any string = {StringEncoding_ASCII}; string.s_char = str; return(string); } -static String_Any +internal String_Any SCany(String_u8 str){ String_Any string = {StringEncoding_UTF8}; string.s_u8 = str; return(string); } -static String_Any +internal String_Any SCany(String_u16 str){ String_Any string = {StringEncoding_UTF16}; string.s_u16 = str; return(string); } -static String_Any +internal String_Any SCany(String_u32 str){ String_Any string = {StringEncoding_UTF32}; string.s_u32 = str; return(string); } -static String_Const_char +internal String_Const_char SCchar(char *str, umem size){ String_Const_char string = {str, size}; return(string); } -static String_Const_u8 +internal String_Const_u8 SCu8(u8 *str, umem size){ String_Const_u8 string = {str, size}; return(string); } -static String_Const_u16 +internal String_Const_u16 SCu16(u16 *str, umem size){ String_Const_u16 string = {str, size}; return(string); } -static String_Const_u32 +internal String_Const_u32 SCu32(u32 *str, umem size){ String_Const_u32 string = {str, size}; return(string); } -static String_Const_Any +internal String_Const_Any SCany(void *str, umem size, String_Encoding encoding){ String_Const_Any string = {encoding}; switch (encoding){ @@ -3058,45 +3249,45 @@ SCany(void *str, umem size, String_Encoding encoding){ return(string); } -static String_Const_char +internal String_Const_char SCchar(void){ String_Const_char string = {}; return(string); } -static String_Const_u8 +internal String_Const_u8 SCu8(void){ String_Const_u8 string = {}; return(string); } -static String_Const_u16 +internal String_Const_u16 SCu16(void){ String_Const_u16 string = {}; return(string); } -static String_Const_u32 +internal String_Const_u32 SCu32(void){ String_Const_u32 string = {}; return(string); } -static String_Const_char +internal String_Const_char SCchar(char *str, char *one_past_last){ return(SCchar(str, (umem)(one_past_last - str))); } -static String_Const_u8 +internal String_Const_u8 SCu8(u8 *str, u8 *one_past_last){ return(SCu8(str, (umem)(one_past_last - str))); } -static String_Const_u16 +internal String_Const_u16 SCu16(u16 *str, u16 *one_past_last){ return(SCu16(str, (umem)(one_past_last - str))); } -static String_Const_u32 +internal String_Const_u32 SCu32(u32 *str, u32 *one_past_last){ return(SCu32(str, (umem)(one_past_last - str))); } -static String_Const_Any +internal String_Const_Any SCany(void *str, void *one_past_last, String_Encoding encoding){ String_Const_Any string = {encoding}; switch (encoding){ @@ -3108,68 +3299,68 @@ SCany(void *str, void *one_past_last, String_Encoding encoding){ return(string); } -static String_Const_char +internal String_Const_char SCchar(char *str){ umem size = cstring_length(str); String_Const_char string = {str, size}; return(string); } -static String_Const_u8 +internal String_Const_u8 SCu8(u8 *str){ umem size = cstring_length(str); String_Const_u8 string = {str, size}; return(string); } -static String_Const_u16 +internal String_Const_u16 SCu16(u16 *str){ umem size = cstring_length(str); String_Const_u16 string = {str, size}; return(string); } -static String_Const_u32 +internal String_Const_u32 SCu32(u32 *str){ umem size = cstring_length(str); String_Const_u32 string = {str, size}; return(string); } -static String_Const_char +internal String_Const_char SCchar(String_Const_u8 str){ return(SCchar((char*)str.str, str.size)); } -static String_Const_u8 +internal String_Const_u8 SCu8(String_Const_char str){ return(SCu8((u8*)str.str, str.size)); } -static String_Const_u8 +internal String_Const_u8 SCu8(char *str, umem length){ return(SCu8((u8*)str, length)); } -static String_Const_u8 +internal String_Const_u8 SCu8(char *first, char *one_past_last){ return(SCu8((u8*)first, (u8*)one_past_last)); } -static String_Const_u8 +internal String_Const_u8 SCu8(char *str){ return(SCu8((u8*)str)); } -static String_Const_u8 +internal String_Const_u8 SCu8(Data data){ return(SCu8((u8*)data.data, data.size)); } -static String_Const_u16 +internal String_Const_u16 SCu16(wchar_t *str, umem size){ return(SCu16((u16*)str, size)); } -static String_Const_u16 +internal String_Const_u16 SCu16(wchar_t *str){ return(SCu16((u16*)str)); } -static String_Const_Any +internal String_Const_Any SCany(void *str, String_Encoding encoding){ String_Const_Any string = {encoding}; switch (encoding){ @@ -3181,25 +3372,25 @@ SCany(void *str, String_Encoding encoding){ return(string); } -static String_Const_Any +internal String_Const_Any SCany(String_Const_char str){ String_Const_Any string = {StringEncoding_ASCII}; string.s_char = str; return(string); } -static String_Const_Any +internal String_Const_Any SCany(String_Const_u8 str){ String_Const_Any string = {StringEncoding_UTF8}; string.s_u8 = str; return(string); } -static String_Const_Any +internal String_Const_Any SCany(String_Const_u16 str){ String_Const_Any string = {StringEncoding_UTF16}; string.s_u16 = str; return(string); } -static String_Const_Any +internal String_Const_Any SCany(String_Const_u32 str){ String_Const_Any string = {StringEncoding_UTF32}; string.s_u32 = str; @@ -3214,10 +3405,10 @@ SCany(String_Const_u32 str){ #define string_expand(s) (i32)(s).size, (char*)(s).str -static String_Const_char string_empty = {"", 0}; -static String_Const_u8 string_u8_empty = {"", 0}; +internal String_Const_char string_empty = {"", 0}; +internal String_Const_u8 string_u8_empty = {"", 0}; -static char +internal char string_get_character(String_Const_char str, umem i){ char r = 0; if (i < str.size){ @@ -3225,7 +3416,7 @@ string_get_character(String_Const_char str, umem i){ } return(r); } -static u8 +internal u8 string_get_character(String_Const_u8 str, umem i){ u8 r = 0; if (i < str.size){ @@ -3233,7 +3424,7 @@ string_get_character(String_Const_u8 str, umem i){ } return(r); } -static u16 +internal u16 string_get_character(String_Const_u16 str, umem i){ u16 r = 0; if (i < str.size){ @@ -3241,7 +3432,7 @@ string_get_character(String_Const_u16 str, umem i){ } return(r); } -static u32 +internal u32 string_get_character(String_Const_u32 str, umem i){ u32 r = 0; if (i < str.size){ @@ -3250,32 +3441,32 @@ string_get_character(String_Const_u32 str, umem i){ return(r); } -static String_Const_char +internal String_Const_char string_prefix(String_Const_char str, umem size){ size = clamp_top(size, str.size); str.size = size; return(str); } -static String_Const_u8 +internal String_Const_u8 string_prefix(String_Const_u8 str, umem size){ size = clamp_top(size, str.size); str.size = size; return(str); } -static String_Const_u16 +internal String_Const_u16 string_prefix(String_Const_u16 str, umem size){ size = clamp_top(size, str.size); str.size = size; return(str); } -static String_Const_u32 +internal String_Const_u32 string_prefix(String_Const_u32 str, umem size){ size = clamp_top(size, str.size); str.size = size; return(str); } -static String_Const_Any +internal String_Const_Any string_prefix(String_Const_Any str, umem size){ switch (str.encoding){ case StringEncoding_ASCII: str.s_char = string_prefix(str.s_char, size); break; @@ -3286,28 +3477,28 @@ string_prefix(String_Const_Any str, umem size){ return(str); } -static String_Const_char +internal String_Const_char string_postfix(String_Const_char str, umem size){ size = clamp_top(size, str.size); str.str += (str.size - size); str.size = size; return(str); } -static String_Const_u8 +internal String_Const_u8 string_postfix(String_Const_u8 str, umem size){ size = clamp_top(size, str.size); str.str += (str.size - size); str.size = size; return(str); } -static String_Const_u16 +internal String_Const_u16 string_postfix(String_Const_u16 str, umem size){ size = clamp_top(size, str.size); str.str += (str.size - size); str.size = size; return(str); } -static String_Const_u32 +internal String_Const_u32 string_postfix(String_Const_u32 str, umem size){ size = clamp_top(size, str.size); str.str += (str.size - size); @@ -3315,7 +3506,7 @@ string_postfix(String_Const_u32 str, umem size){ return(str); } -static String_Const_Any +internal String_Const_Any string_postfix(String_Const_Any str, umem size){ switch (str.encoding){ case StringEncoding_ASCII: str.s_char = string_postfix(str.s_char, size); break; @@ -3326,28 +3517,28 @@ string_postfix(String_Const_Any str, umem size){ return(str); } -static String_Const_char +internal String_Const_char string_skip(String_Const_char str, umem n){ n = clamp_top(n, str.size); str.str += n;; str.size -= n; return(str); } -static String_Const_u8 +internal String_Const_u8 string_skip(String_Const_u8 str, umem n){ n = clamp_top(n, str.size); str.str += n;; str.size -= n; return(str); } -static String_Const_u16 +internal String_Const_u16 string_skip(String_Const_u16 str, umem n){ n = clamp_top(n, str.size); str.str += n;; str.size -= n; return(str); } -static String_Const_u32 +internal String_Const_u32 string_skip(String_Const_u32 str, umem n){ n = clamp_top(n, str.size); str.str += n;; @@ -3355,7 +3546,7 @@ string_skip(String_Const_u32 str, umem n){ return(str); } -static String_Const_Any +internal String_Const_Any string_skip(String_Const_Any str, umem n){ switch (str.encoding){ case StringEncoding_ASCII: str.s_char = string_skip(str.s_char, n); break; @@ -3366,32 +3557,32 @@ string_skip(String_Const_Any str, umem n){ return(str); } -static String_Const_char +internal String_Const_char string_chop(String_Const_char str, umem n){ n = clamp_top(n, str.size); str.size -= n; return(str); } -static String_Const_u8 +internal String_Const_u8 string_chop(String_Const_u8 str, umem n){ n = clamp_top(n, str.size); str.size -= n; return(str); } -static String_Const_u16 +internal String_Const_u16 string_chop(String_Const_u16 str, umem n){ n = clamp_top(n, str.size); str.size -= n; return(str); } -static String_Const_u32 +internal String_Const_u32 string_chop(String_Const_u32 str, umem n){ n = clamp_top(n, str.size); str.size -= n; return(str); } -static String_Const_Any +internal String_Const_Any string_chop(String_Const_Any str, umem n){ switch (str.encoding){ case StringEncoding_ASCII: str.s_char = string_chop(str.s_char, n); break; @@ -3402,87 +3593,87 @@ string_chop(String_Const_Any str, umem n){ return(str); } -static String_Const_char +internal String_Const_char string_substring(String_Const_char str, Range_i64 range){ return(SCchar(str.str + range.min, str.str + range.max)); } -static String_Const_u8 +internal String_Const_u8 string_substring(String_Const_u8 str, Range_i64 range){ return(SCu8(str.str + range.min, str.str + range.max)); } -static String_Const_u16 +internal String_Const_u16 string_substring(String_Const_u16 str, Range_i64 range){ return(SCu16(str.str + range.min, str.str + range.max)); } -static String_Const_u32 +internal String_Const_u32 string_substring(String_Const_u32 str, Range_i64 range){ return(SCu32(str.str + range.min, str.str + range.max)); } -static umem +internal umem string_find_first(String_Const_char str, umem start_pos, char c){ umem i = start_pos; for (;i < str.size && c != str.str[i]; i += 1); return(i); } -static umem +internal umem string_find_first(String_Const_u8 str, umem start_pos, u8 c){ umem i = start_pos; for (;i < str.size && c != str.str[i]; i += 1); return(i); } -static umem +internal umem string_find_first(String_Const_u16 str, umem start_pos, u16 c){ umem i = start_pos; for (;i < str.size && c != str.str[i]; i += 1); return(i); } -static umem +internal umem string_find_first(String_Const_u32 str, umem start_pos, u32 c){ umem i = start_pos; for (;i < str.size && c != str.str[i]; i += 1); return(i); } -static umem +internal umem string_find_first(String_Const_char str, char c){ return(string_find_first(str, 0, c)); } -static umem +internal umem string_find_first(String_Const_u8 str, u8 c){ return(string_find_first(str, 0, c)); } -static umem +internal umem string_find_first(String_Const_u16 str, u16 c){ return(string_find_first(str, 0, c)); } -static umem +internal umem string_find_first(String_Const_u32 str, u32 c){ return(string_find_first(str, 0, c)); } -static imem +internal imem string_find_last(String_Const_char str, char c){ imem size = (imem)str.size; imem i = size - 1; for (;i >= 0 && c != str.str[i]; i -= 1); return(i); } -static imem +internal imem string_find_last(String_Const_u8 str, u8 c){ imem size = (imem)str.size; imem i = size - 1; for (;i >= 0 && c != str.str[i]; i -= 1); return(i); } -static imem +internal imem string_find_last(String_Const_u16 str, u16 c){ imem size = (imem)str.size; imem i = size - 1; for (;i >= 0 && c != str.str[i]; i -= 1); return(i); } -static imem +internal imem string_find_last(String_Const_u32 str, u32 c){ imem size = (imem)str.size; imem i = size - 1; @@ -3490,52 +3681,52 @@ string_find_last(String_Const_u32 str, u32 c){ return(i); } -static umem +internal umem string_find_first_whitespace(String_Const_char str){ umem i = 0; for (;i < str.size && !character_is_whitespace(str.str[i]); i += 1); return(i); } -static umem +internal umem string_find_first_whitespace(String_Const_u8 str){ umem i = 0; for (;i < str.size && !character_is_whitespace(str.str[i]); i += 1); return(i); } -static umem +internal umem string_find_first_whitespace(String_Const_u16 str){ umem i = 0; for (;i < str.size && !character_is_whitespace(str.str[i]); i += 1); return(i); } -static umem +internal umem string_find_first_whitespace(String_Const_u32 str){ umem i = 0; for (;i < str.size && !character_is_whitespace(str.str[i]); i += 1); return(i); } -static imem +internal imem string_find_last_whitespace(String_Const_char str){ imem size = (imem)str.size; imem i = size - 1; for (;i >= 0 && !character_is_whitespace(str.str[i]); i -= 1); return(i); } -static imem +internal imem string_find_last_whitespace(String_Const_u8 str){ imem size = (imem)str.size; imem i = size - 1; for (;i >= 0 && !character_is_whitespace(str.str[i]); i -= 1); return(i); } -static imem +internal imem string_find_last_whitespace(String_Const_u16 str){ imem size = (imem)str.size; imem i = size - 1; for (;i >= 0 && !character_is_whitespace(str.str[i]); i -= 1); return(i); } -static imem +internal imem string_find_last_whitespace(String_Const_u32 str){ imem size = (imem)str.size; imem i = size - 1; @@ -3543,52 +3734,52 @@ string_find_last_whitespace(String_Const_u32 str){ return(i); } -static umem +internal umem string_find_first_non_whitespace(String_Const_char str){ umem i = 0; for (;i < str.size && character_is_whitespace(str.str[i]); i += 1); return(i); } -static umem +internal umem string_find_first_non_whitespace(String_Const_u8 str){ umem i = 0; for (;i < str.size && character_is_whitespace(str.str[i]); i += 1); return(i); } -static umem +internal umem string_find_first_non_whitespace(String_Const_u16 str){ umem i = 0; for (;i < str.size && character_is_whitespace(str.str[i]); i += 1); return(i); } -static umem +internal umem string_find_first_non_whitespace(String_Const_u32 str){ umem i = 0; for (;i < str.size && character_is_whitespace(str.str[i]); i += 1); return(i); } -static imem +internal imem string_find_last_non_whitespace(String_Const_char str){ imem size = (imem)str.size; imem i = size - 1; for (;i >= 0 && character_is_whitespace(str.str[i]); i -= 1); return(i); } -static imem +internal imem string_find_last_non_whitespace(String_Const_u8 str){ imem size = (imem)str.size; imem i = size - 1; for (;i >= 0 && character_is_whitespace(str.str[i]); i -= 1); return(i); } -static imem +internal imem string_find_last_non_whitespace(String_Const_u16 str){ imem size = (imem)str.size; imem i = size - 1; for (;i >= 0 && character_is_whitespace(str.str[i]); i -= 1); return(i); } -static imem +internal imem string_find_last_non_whitespace(String_Const_u32 str){ imem size = (imem)str.size; imem i = size - 1; @@ -3596,52 +3787,52 @@ string_find_last_non_whitespace(String_Const_u32 str){ return(i); } -static umem +internal umem string_find_first_slash(String_Const_char str){ umem i = 0; for (;i < str.size && !character_is_slash(str.str[i]); i += 1); return(i); } -static umem +internal umem string_find_first_slash(String_Const_u8 str){ umem i = 0; for (;i < str.size && !character_is_slash(str.str[i]); i += 1); return(i); } -static umem +internal umem string_find_first_slash(String_Const_u16 str){ umem i = 0; for (;i < str.size && !character_is_slash(str.str[i]); i += 1); return(i); } -static umem +internal umem string_find_first_slash(String_Const_u32 str){ umem i = 0; for (;i < str.size && !character_is_slash(str.str[i]); i += 1); return(i); } -static imem +internal imem string_find_last_slash(String_Const_char str){ imem size = (imem)str.size; imem i = size - 1; for (;i >= 0 && !character_is_slash(str.str[i]); i -= 1); return(i); } -static imem +internal imem string_find_last_slash(String_Const_u8 str){ imem size = (imem)str.size; imem i = size - 1; for (;i >= 0 && !character_is_slash(str.str[i]); i -= 1); return(i); } -static imem +internal imem string_find_last_slash(String_Const_u16 str){ imem size = (imem)str.size; imem i = size - 1; for (;i >= 0 && !character_is_slash(str.str[i]); i -= 1); return(i); } -static imem +internal imem string_find_last_slash(String_Const_u32 str){ imem size = (imem)str.size; imem i = size - 1; @@ -3649,7 +3840,7 @@ string_find_last_slash(String_Const_u32 str){ return(i); } -static String_Const_char +internal String_Const_char string_remove_last_folder(String_Const_char str){ if (str.size > 0){ str.size -= 1; @@ -3663,7 +3854,7 @@ string_remove_last_folder(String_Const_char str){ } return(str); } -static String_Const_u8 +internal String_Const_u8 string_remove_last_folder(String_Const_u8 str){ if (str.size > 0){ str.size -= 1; @@ -3677,7 +3868,7 @@ string_remove_last_folder(String_Const_u8 str){ } return(str); } -static String_Const_u16 +internal String_Const_u16 string_remove_last_folder(String_Const_u16 str){ if (str.size > 0){ str.size -= 1; @@ -3691,7 +3882,7 @@ string_remove_last_folder(String_Const_u16 str){ } return(str); } -static String_Const_u32 +internal String_Const_u32 string_remove_last_folder(String_Const_u32 str){ if (str.size > 0){ str.size -= 1; @@ -3706,7 +3897,7 @@ string_remove_last_folder(String_Const_u32 str){ return(str); } -static String_Const_char +internal String_Const_char string_remove_front_of_path(String_Const_char str){ imem slash_pos = string_find_last_slash(str); if (slash_pos < 0){ @@ -3717,7 +3908,7 @@ string_remove_front_of_path(String_Const_char str){ } return(str); } -static String_Const_u8 +internal String_Const_u8 string_remove_front_of_path(String_Const_u8 str){ imem slash_pos = string_find_last_slash(str); if (slash_pos < 0){ @@ -3728,7 +3919,7 @@ string_remove_front_of_path(String_Const_u8 str){ } return(str); } -static String_Const_u16 +internal String_Const_u16 string_remove_front_of_path(String_Const_u16 str){ imem slash_pos = string_find_last_slash(str); if (slash_pos < 0){ @@ -3739,7 +3930,7 @@ string_remove_front_of_path(String_Const_u16 str){ } return(str); } -static String_Const_u32 +internal String_Const_u32 string_remove_front_of_path(String_Const_u32 str){ imem slash_pos = string_find_last_slash(str); if (slash_pos < 0){ @@ -3751,7 +3942,7 @@ string_remove_front_of_path(String_Const_u32 str){ return(str); } -static String_Const_char +internal String_Const_char string_front_of_path(String_Const_char str){ imem slash_pos = string_find_last_slash(str); if (slash_pos >= 0){ @@ -3759,7 +3950,7 @@ string_front_of_path(String_Const_char str){ } return(str); } -static String_Const_u8 +internal String_Const_u8 string_front_of_path(String_Const_u8 str){ imem slash_pos = string_find_last_slash(str); if (slash_pos >= 0){ @@ -3767,7 +3958,7 @@ string_front_of_path(String_Const_u8 str){ } return(str); } -static String_Const_u16 +internal String_Const_u16 string_front_of_path(String_Const_u16 str){ imem slash_pos = string_find_last_slash(str); if (slash_pos >= 0){ @@ -3775,7 +3966,7 @@ string_front_of_path(String_Const_u16 str){ } return(str); } -static String_Const_u32 +internal String_Const_u32 string_front_of_path(String_Const_u32 str){ imem slash_pos = string_find_last_slash(str); if (slash_pos >= 0){ @@ -3784,24 +3975,24 @@ string_front_of_path(String_Const_u32 str){ return(str); } -static String_Const_char +internal String_Const_char string_file_extension(String_Const_char string){ return(string_skip(string, string_find_last(string, '.') + 1)); } -static String_Const_u8 +internal String_Const_u8 string_file_extension(String_Const_u8 string){ return(string_skip(string, string_find_last(string, '.') + 1)); } -static String_Const_u16 +internal String_Const_u16 string_file_extension(String_Const_u16 string){ return(string_skip(string, string_find_last(string, '.') + 1)); } -static String_Const_u32 +internal String_Const_u32 string_file_extension(String_Const_u32 string){ return(string_skip(string, string_find_last(string, '.') + 1)); } -static String_Const_char +internal String_Const_char string_file_without_extension(String_Const_char string){ imem pos = string_find_last(string, '.'); if (pos > 0){ @@ -3809,7 +4000,7 @@ string_file_without_extension(String_Const_char string){ } return(string); } -static String_Const_u8 +internal String_Const_u8 string_file_without_extension(String_Const_u8 string){ imem pos = string_find_last(string, '.'); if (pos > 0){ @@ -3817,7 +4008,7 @@ string_file_without_extension(String_Const_u8 string){ } return(string); } -static String_Const_u16 +internal String_Const_u16 string_file_without_extension(String_Const_u16 string){ imem pos = string_find_last(string, '.'); if (pos > 0){ @@ -3825,7 +4016,7 @@ string_file_without_extension(String_Const_u16 string){ } return(string); } -static String_Const_u32 +internal String_Const_u32 string_file_without_extension(String_Const_u32 string){ imem pos = string_find_last(string, '.'); if (pos > 0){ @@ -3834,57 +4025,57 @@ string_file_without_extension(String_Const_u32 string){ return(string); } -static String_Const_char +internal String_Const_char string_skip_whitespace(String_Const_char str){ umem f = string_find_first_non_whitespace(str); str = string_skip(str, f); return(str); } -static String_Const_u8 +internal String_Const_u8 string_skip_whitespace(String_Const_u8 str){ umem f = string_find_first_non_whitespace(str); str = string_skip(str, f); return(str); } -static String_Const_u16 +internal String_Const_u16 string_skip_whitespace(String_Const_u16 str){ umem f = string_find_first_non_whitespace(str); str = string_skip(str, f); return(str); } -static String_Const_u32 +internal String_Const_u32 string_skip_whitespace(String_Const_u32 str){ umem f = string_find_first_non_whitespace(str); str = string_skip(str, f); return(str); } -static String_Const_char +internal String_Const_char string_chop_whitespace(String_Const_char str){ imem e = string_find_last_non_whitespace(str); str = string_prefix(str, (umem)(e + 1)); return(str); } -static String_Const_u8 +internal String_Const_u8 string_chop_whitespace(String_Const_u8 str){ imem e = string_find_last_non_whitespace(str); str = string_prefix(str, (umem)(e + 1)); return(str); } -static String_Const_u16 +internal String_Const_u16 string_chop_whitespace(String_Const_u16 str){ imem e = string_find_last_non_whitespace(str); str = string_prefix(str, (umem)(e + 1)); return(str); } -static String_Const_u32 +internal String_Const_u32 string_chop_whitespace(String_Const_u32 str){ imem e = string_find_last_non_whitespace(str); str = string_prefix(str, (umem)(e + 1)); return(str); } -static String_Const_char +internal String_Const_char string_skip_chop_whitespace(String_Const_char str){ umem f = string_find_first_non_whitespace(str); str = string_skip(str, f); @@ -3892,7 +4083,7 @@ string_skip_chop_whitespace(String_Const_char str){ str = string_prefix(str, (umem)(e + 1)); return(str); } -static String_Const_u8 +internal String_Const_u8 string_skip_chop_whitespace(String_Const_u8 str){ umem f = string_find_first_non_whitespace(str); str = string_skip(str, f); @@ -3900,7 +4091,7 @@ string_skip_chop_whitespace(String_Const_u8 str){ str = string_prefix(str, (umem)(e + 1)); return(str); } -static String_Const_u16 +internal String_Const_u16 string_skip_chop_whitespace(String_Const_u16 str){ umem f = string_find_first_non_whitespace(str); str = string_skip(str, f); @@ -3908,7 +4099,7 @@ string_skip_chop_whitespace(String_Const_u16 str){ str = string_prefix(str, (umem)(e + 1)); return(str); } -static String_Const_u32 +internal String_Const_u32 string_skip_chop_whitespace(String_Const_u32 str){ umem f = string_find_first_non_whitespace(str); str = string_skip(str, f); @@ -3917,7 +4108,7 @@ string_skip_chop_whitespace(String_Const_u32 str){ return(str); } -static b32 +internal b32 string_match(String_Const_char a, String_Const_char b){ b32 result = false; if (a.size == b.size){ @@ -3931,7 +4122,7 @@ string_match(String_Const_char a, String_Const_char b){ } return(result); } -static b32 +internal b32 string_match(String_Const_u8 a, String_Const_u8 b){ b32 result = false; if (a.size == b.size){ @@ -3945,7 +4136,7 @@ string_match(String_Const_u8 a, String_Const_u8 b){ } return(result); } -static b32 +internal b32 string_match(String_Const_u16 a, String_Const_u16 b){ b32 result = false; if (a.size == b.size){ @@ -3959,7 +4150,7 @@ string_match(String_Const_u16 a, String_Const_u16 b){ } return(result); } -static b32 +internal b32 string_match(String_Const_u32 a, String_Const_u32 b){ b32 result = false; if (a.size == b.size){ @@ -3974,7 +4165,7 @@ string_match(String_Const_u32 a, String_Const_u32 b){ return(result); } -static b32 +internal b32 string_match(String_Const_Any a, String_Const_Any b){ b32 result = false; if (a.encoding == b.encoding){ @@ -3988,7 +4179,7 @@ string_match(String_Const_Any a, String_Const_Any b){ return(result); } -static b32 +internal b32 string_match_insensitive(String_Const_char a, String_Const_char b){ b32 result = false; if (a.size == b.size){ @@ -4002,7 +4193,7 @@ string_match_insensitive(String_Const_char a, String_Const_char b){ } return(result); } -static b32 +internal b32 string_match_insensitive(String_Const_u8 a, String_Const_u8 b){ b32 result = false; if (a.size == b.size){ @@ -4016,7 +4207,7 @@ string_match_insensitive(String_Const_u8 a, String_Const_u8 b){ } return(result); } -static b32 +internal b32 string_match_insensitive(String_Const_u16 a, String_Const_u16 b){ b32 result = false; if (a.size == b.size){ @@ -4030,7 +4221,7 @@ string_match_insensitive(String_Const_u16 a, String_Const_u16 b){ } return(result); } -static b32 +internal b32 string_match_insensitive(String_Const_u32 a, String_Const_u32 b){ b32 result = false; if (a.size == b.size){ @@ -4045,7 +4236,7 @@ string_match_insensitive(String_Const_u32 a, String_Const_u32 b){ return(result); } -static b32 +internal b32 string_match(String_Const_char a, String_Const_char b, String_Match_Rule rule){ b32 result = false; switch (rule){ @@ -4060,7 +4251,7 @@ string_match(String_Const_char a, String_Const_char b, String_Match_Rule rule){ } return(result); } -static b32 +internal b32 string_match(String_Const_u8 a, String_Const_u8 b, String_Match_Rule rule){ b32 result = false; switch (rule){ @@ -4075,7 +4266,7 @@ string_match(String_Const_u8 a, String_Const_u8 b, String_Match_Rule rule){ } return(result); } -static b32 +internal b32 string_match(String_Const_u16 a, String_Const_u16 b, String_Match_Rule rule){ b32 result = false; switch (rule){ @@ -4090,7 +4281,7 @@ string_match(String_Const_u16 a, String_Const_u16 b, String_Match_Rule rule){ } return(result); } -static b32 +internal b32 string_match(String_Const_u32 a, String_Const_u32 b, String_Match_Rule rule){ b32 result = false; switch (rule){ @@ -4106,7 +4297,7 @@ string_match(String_Const_u32 a, String_Const_u32 b, String_Match_Rule rule){ return(result); } -static umem +internal umem string_find_first(String_Const_char str, String_Const_char needle, String_Match_Rule rule){ umem i = 0; if (needle.size > 0){ @@ -4129,7 +4320,7 @@ string_find_first(String_Const_char str, String_Const_char needle, String_Match_ } return(i); } -static umem +internal umem string_find_first(String_Const_u8 str, String_Const_u8 needle, String_Match_Rule rule){ umem i = 0; if (needle.size > 0){ @@ -4152,7 +4343,7 @@ string_find_first(String_Const_u8 str, String_Const_u8 needle, String_Match_Rule } return(i); } -static umem +internal umem string_find_first(String_Const_u16 str, String_Const_u16 needle, String_Match_Rule rule){ umem i = 0; if (needle.size > 0){ @@ -4175,7 +4366,7 @@ string_find_first(String_Const_u16 str, String_Const_u16 needle, String_Match_Ru } return(i); } -static umem +internal umem string_find_first(String_Const_u32 str, String_Const_u32 needle, String_Match_Rule rule){ umem i = 0; if (needle.size > 0){ @@ -4199,40 +4390,40 @@ string_find_first(String_Const_u32 str, String_Const_u32 needle, String_Match_Ru return(i); } -static umem +internal umem string_find_first(String_Const_char str, String_Const_char needle){ return(string_find_first(str, needle, StringMatch_Exact)); } -static umem +internal umem string_find_first(String_Const_u8 str, String_Const_u8 needle){ return(string_find_first(str, needle, StringMatch_Exact)); } -static umem +internal umem string_find_first(String_Const_u16 str, String_Const_u16 needle){ return(string_find_first(str, needle, StringMatch_Exact)); } -static umem +internal umem string_find_first(String_Const_u32 str, String_Const_u32 needle){ return(string_find_first(str, needle, StringMatch_Exact)); } -static umem +internal umem string_find_first_insensitive(String_Const_char str, String_Const_char needle){ return(string_find_first(str, needle, StringMatch_CaseInsensitive)); } -static umem +internal umem string_find_first_insensitive(String_Const_u8 str, String_Const_u8 needle){ return(string_find_first(str, needle, StringMatch_CaseInsensitive)); } -static umem +internal umem string_find_first_insensitive(String_Const_u16 str, String_Const_u16 needle){ return(string_find_first(str, needle, StringMatch_CaseInsensitive)); } -static umem +internal umem string_find_first_insensitive(String_Const_u32 str, String_Const_u32 needle){ return(string_find_first(str, needle, StringMatch_CaseInsensitive)); } -static i32 +internal i32 string_compare(String_Const_char a, String_Const_char b){ i32 result = 0; for (umem i = 0; i < a.size || i < b.size; i += 1){ @@ -4246,7 +4437,7 @@ string_compare(String_Const_char a, String_Const_char b){ } return(result); } -static i32 +internal i32 string_compare(String_Const_u8 a, String_Const_u8 b){ i32 result = 0; for (umem i = 0; i < a.size || i < b.size; i += 1){ @@ -4260,7 +4451,7 @@ string_compare(String_Const_u8 a, String_Const_u8 b){ } return(result); } -static i32 +internal i32 string_compare(String_Const_u16 a, String_Const_u16 b){ i32 result = 0; for (umem i = 0; i < a.size || i < b.size; i += 1){ @@ -4274,7 +4465,7 @@ string_compare(String_Const_u16 a, String_Const_u16 b){ } return(result); } -static i32 +internal i32 string_compare(String_Const_u32 a, String_Const_u32 b){ i32 result = 0; for (umem i = 0; i < a.size || i < b.size; i += 1){ @@ -4289,7 +4480,7 @@ string_compare(String_Const_u32 a, String_Const_u32 b){ return(result); } -static i32 +internal i32 string_compare_insensitive(String_Const_char a, String_Const_char b){ i32 result = 0; for (umem i = 0; i < a.size || i < b.size; i += 1){ @@ -4303,7 +4494,7 @@ string_compare_insensitive(String_Const_char a, String_Const_char b){ } return(result); } -static i32 +internal i32 string_compare_insensitive(String_Const_u8 a, String_Const_u8 b){ i32 result = 0; for (umem i = 0; i < a.size || i < b.size; i += 1){ @@ -4317,7 +4508,7 @@ string_compare_insensitive(String_Const_u8 a, String_Const_u8 b){ } return(result); } -static i32 +internal i32 string_compare_insensitive(String_Const_u16 a, String_Const_u16 b){ i32 result = 0; for (umem i = 0; i < a.size || i < b.size; i += 1){ @@ -4331,7 +4522,7 @@ string_compare_insensitive(String_Const_u16 a, String_Const_u16 b){ } return(result); } -static i32 +internal i32 string_compare_insensitive(String_Const_u32 a, String_Const_u32 b){ i32 result = 0; for (umem i = 0; i < a.size || i < b.size; i += 1){ @@ -4346,56 +4537,56 @@ string_compare_insensitive(String_Const_u32 a, String_Const_u32 b){ return(result); } -static String_Const_char +internal String_Const_char string_mod_upper(String_Const_char str){ for (umem i = 0; i < str.size; i += 1){ str.str[i] = character_to_upper(str.str[i]); } return(str); } -static String_Const_u8 +internal String_Const_u8 string_mod_upper(String_Const_u8 str){ for (umem i = 0; i < str.size; i += 1){ str.str[i] = character_to_upper(str.str[i]); } return(str); } -static String_Const_u16 +internal String_Const_u16 string_mod_upper(String_Const_u16 str){ for (umem i = 0; i < str.size; i += 1){ str.str[i] = character_to_upper(str.str[i]); } return(str); } -static String_Const_u32 +internal String_Const_u32 string_mod_upper(String_Const_u32 str){ for (umem i = 0; i < str.size; i += 1){ str.str[i] = character_to_upper(str.str[i]); } return(str); } -static String_Const_char +internal String_Const_char string_mod_lower(String_Const_char str){ for (umem i = 0; i < str.size; i += 1){ str.str[i] = character_to_lower(str.str[i]); } return(str); } -static String_Const_u8 +internal String_Const_u8 string_mod_lower(String_Const_u8 str){ for (umem i = 0; i < str.size; i += 1){ str.str[i] = character_to_lower(str.str[i]); } return(str); } -static String_Const_u16 +internal String_Const_u16 string_mod_lower(String_Const_u16 str){ for (umem i = 0; i < str.size; i += 1){ str.str[i] = character_to_lower(str.str[i]); } return(str); } -static String_Const_u32 +internal String_Const_u32 string_mod_lower(String_Const_u32 str){ for (umem i = 0; i < str.size; i += 1){ str.str[i] = character_to_lower(str.str[i]); @@ -4403,7 +4594,7 @@ string_mod_lower(String_Const_u32 str){ return(str); } -static String_Const_char +internal String_Const_char string_mod_replace_character(String_Const_char str, char o, char n){ for (umem i = 0; i < str.size; i += 1){ char c = str.str[i]; @@ -4411,7 +4602,7 @@ string_mod_replace_character(String_Const_char str, char o, char n){ } return(str); } -static String_Const_u8 +internal String_Const_u8 string_mod_replace_character(String_Const_u8 str, u8 o, u8 n){ for (umem i = 0; i < str.size; i += 1){ u8 c = str.str[i]; @@ -4419,7 +4610,7 @@ string_mod_replace_character(String_Const_u8 str, u8 o, u8 n){ } return(str); } -static String_Const_u16 +internal String_Const_u16 string_mod_replace_character(String_Const_u16 str, u16 o, u16 n){ for (umem i = 0; i < str.size; i += 1){ u16 c = str.str[i]; @@ -4427,7 +4618,7 @@ string_mod_replace_character(String_Const_u16 str, u16 o, u16 n){ } return(str); } -static String_Const_u32 +internal String_Const_u32 string_mod_replace_character(String_Const_u32 str, u32 o, u32 n){ for (umem i = 0; i < str.size; i += 1){ u32 c = str.str[i]; @@ -4436,7 +4627,7 @@ string_mod_replace_character(String_Const_u32 str, u32 o, u32 n){ return(str); } -static b32 +internal b32 string_append(String_char *dst, String_Const_char src){ b32 result = false; umem available = dst->cap - dst->size; @@ -4448,7 +4639,7 @@ string_append(String_char *dst, String_Const_char src){ dst->size += copy_size; return(result); } -static b32 +internal b32 string_append(String_u8 *dst, String_Const_u8 src){ b32 result = false; umem available = dst->cap - dst->size; @@ -4460,7 +4651,7 @@ string_append(String_u8 *dst, String_Const_u8 src){ dst->size += copy_size; return(result); } -static b32 +internal b32 string_append(String_u16 *dst, String_Const_u16 src){ b32 result = false; umem available = dst->cap - dst->size; @@ -4472,7 +4663,7 @@ string_append(String_u16 *dst, String_Const_u16 src){ dst->size += copy_size; return(result); } -static b32 +internal b32 string_append(String_u32 *dst, String_Const_u32 src){ b32 result = false; umem available = dst->cap - dst->size; @@ -4485,24 +4676,24 @@ string_append(String_u32 *dst, String_Const_u32 src){ return(result); } -static b32 +internal b32 string_append_character(String_char *dst, char c){ return(string_append(dst, SCchar(&c, 1))); } -static b32 +internal b32 string_append_character(String_u8 *dst, u8 c){ return(string_append(dst, SCu8(&c, 1))); } -static b32 +internal b32 string_append_character(String_u16 *dst, u16 c){ return(string_append(dst, SCu16(&c, 1))); } -static b32 +internal b32 string_append_character(String_u32 *dst, u32 c){ return(string_append(dst, SCu32(&c, 1))); } -static b32 +internal b32 string_null_terminate(String_char *str){ b32 result = false; if (str->size < str->cap){ @@ -4510,7 +4701,7 @@ string_null_terminate(String_char *str){ } return(result); } -static b32 +internal b32 string_null_terminate(String_u8 *str){ b32 result = false; if (str->size < str->cap){ @@ -4518,7 +4709,7 @@ string_null_terminate(String_u8 *str){ } return(result); } -static b32 +internal b32 string_null_terminate(String_u16 *str){ b32 result = false; if (str->size < str->cap){ @@ -4526,7 +4717,7 @@ string_null_terminate(String_u16 *str){ } return(result); } -static b32 +internal b32 string_null_terminate(String_u32 *str){ b32 result = false; if (str->size < str->cap){ @@ -4535,28 +4726,28 @@ string_null_terminate(String_u32 *str){ return(result); } -static String_char +internal String_char string_char_push(Arena *arena, umem size){ String_char string = {}; string.str = push_array(arena, char, size); string.cap = size; return(string); } -static String_u8 +internal String_u8 string_u8_push(Arena *arena, umem size){ String_u8 string = {}; string.str = push_array(arena, u8, size); string.cap = size; return(string); } -static String_u16 +internal String_u16 string_u16_push(Arena *arena, umem size){ String_u16 string = {}; string.str = push_array(arena, u16, size); string.cap = size; return(string); } -static String_u32 +internal String_u32 string_u32_push(Arena *arena, umem size){ String_u32 string = {}; string.str = push_array(arena, u32, size); @@ -4564,7 +4755,7 @@ string_u32_push(Arena *arena, umem size){ return(string); } -static String_Any +internal String_Any string_any_push(Arena *arena, umem size, String_Encoding encoding){ String_Any string = {}; switch (encoding){ @@ -4576,28 +4767,28 @@ string_any_push(Arena *arena, umem size, String_Encoding encoding){ return(string); } -static String_Const_char +internal String_Const_char string_const_char_push(Arena *arena, umem size){ String_Const_char string = {}; string.str = push_array(arena, char, size); string.size = size; return(string); } -static String_Const_u8 +internal String_Const_u8 string_const_u8_push(Arena *arena, umem size){ String_Const_u8 string = {}; string.str = push_array(arena, u8, size); string.size = size; return(string); } -static String_Const_u16 +internal String_Const_u16 string_const_u16_push(Arena *arena, umem size){ String_Const_u16 string = {}; string.str = push_array(arena, u16, size); string.size = size; return(string); } -static String_Const_u32 +internal String_Const_u32 string_const_u32_push(Arena *arena, umem size){ String_Const_u32 string = {}; string.str = push_array(arena, u32, size); @@ -4605,7 +4796,7 @@ string_const_u32_push(Arena *arena, umem size){ return(string); } -static String_Const_Any +internal String_Const_Any string_const_any_push(Arena *arena, umem size, String_Encoding encoding){ String_Const_Any string = {}; switch (encoding){ @@ -4617,7 +4808,7 @@ string_const_any_push(Arena *arena, umem size, String_Encoding encoding){ return(string); } -static String_Const_char +internal String_Const_char push_string_copy(Arena *arena, String_Const_char src){ String_Const_char string = {}; string.str = push_array(arena, char, src.size + 1); @@ -4626,7 +4817,7 @@ push_string_copy(Arena *arena, String_Const_char src){ string.str[string.size] = 0; return(string); } -static String_Const_u8 +internal String_Const_u8 push_string_copy(Arena *arena, String_Const_u8 src){ String_Const_u8 string = {}; string.str = push_array(arena, u8, src.size + 1); @@ -4635,7 +4826,7 @@ push_string_copy(Arena *arena, String_Const_u8 src){ string.str[string.size] = 0; return(string); } -static String_Const_u16 +internal String_Const_u16 push_string_copy(Arena *arena, String_Const_u16 src){ String_Const_u16 string = {}; string.str = push_array(arena, u16, src.size + 1); @@ -4644,7 +4835,7 @@ push_string_copy(Arena *arena, String_Const_u16 src){ string.str[string.size] = 0; return(string); } -static String_Const_u32 +internal String_Const_u32 push_string_copy(Arena *arena, String_Const_u32 src){ String_Const_u32 string = {}; string.str = push_array(arena, u32, src.size + 1); @@ -4654,7 +4845,7 @@ push_string_copy(Arena *arena, String_Const_u32 src){ return(string); } -static String_Const_Any +internal String_Const_Any push_string_copy(Arena *arena, umem size, String_Const_Any src){ String_Const_Any string = {}; switch (src.encoding){ @@ -4666,7 +4857,7 @@ push_string_copy(Arena *arena, umem size, String_Const_Any src){ return(string); } -static void +internal void string_list_push(Arena *arena, List_String_Const_char *list, String_Const_char string){ Node_String_Const_char *node = push_array(arena, Node_String_Const_char, 1); sll_queue_push(list->first, list->last, node); @@ -4674,7 +4865,7 @@ string_list_push(Arena *arena, List_String_Const_char *list, String_Const_char s list->node_count += 1; list->total_size += string.size; } -static void +internal void string_list_push(Arena *arena, List_String_Const_u8 *list, String_Const_u8 string){ Node_String_Const_u8 *node = push_array(arena, Node_String_Const_u8, 1); sll_queue_push(list->first, list->last, node); @@ -4682,7 +4873,7 @@ string_list_push(Arena *arena, List_String_Const_u8 *list, String_Const_u8 strin list->node_count += 1; list->total_size += string.size; } -static void +internal void string_list_push(Arena *arena, List_String_Const_u16 *list, String_Const_u16 string){ Node_String_Const_u16 *node = push_array(arena, Node_String_Const_u16, 1); sll_queue_push(list->first, list->last, node); @@ -4690,7 +4881,7 @@ string_list_push(Arena *arena, List_String_Const_u16 *list, String_Const_u16 str list->node_count += 1; list->total_size += string.size; } -static void +internal void string_list_push(Arena *arena, List_String_Const_u32 *list, String_Const_u32 string){ Node_String_Const_u32 *node = push_array(arena, Node_String_Const_u32, 1); sll_queue_push(list->first, list->last, node); @@ -4699,7 +4890,7 @@ string_list_push(Arena *arena, List_String_Const_u32 *list, String_Const_u32 str list->total_size += string.size; } -static void +internal void string_list_push(Arena *arena, List_String_Const_Any *list, String_Const_Any string){ Node_String_Const_Any *node = push_array(arena, Node_String_Const_Any, 1); sll_queue_push(list->first, list->last, node); @@ -4711,28 +4902,28 @@ string_list_push(Arena *arena, List_String_Const_Any *list, String_Const_Any str #define string_list_push_lit(a,l,s) string_list_push((a), (l), string_litexpr(s)) #define string_list_push_u8_lit(a,l,s) string_list_push((a), (l), string_u8_litexpr(s)) -static void +internal void string_list_push(List_String_Const_char *list, List_String_Const_char *src_list){ sll_queue_push_multiple(list->first, list->last, src_list->first, src_list->last); list->node_count += src_list->node_count; list->total_size += src_list->total_size; block_zero_array(src_list); } -static void +internal void string_list_push(List_String_Const_u8 *list, List_String_Const_u8 *src_list){ sll_queue_push_multiple(list->first, list->last, src_list->first, src_list->last); list->node_count += src_list->node_count; list->total_size += src_list->total_size; block_zero_array(src_list); } -static void +internal void string_list_push(List_String_Const_u16 *list, List_String_Const_u16 *src_list){ sll_queue_push_multiple(list->first, list->last, src_list->first, src_list->last); list->node_count += src_list->node_count; list->total_size += src_list->total_size; block_zero_array(src_list); } -static void +internal void string_list_push(List_String_Const_u32 *list, List_String_Const_u32 *src_list){ sll_queue_push_multiple(list->first, list->last, src_list->first, src_list->last); list->node_count += src_list->node_count; @@ -4740,7 +4931,7 @@ string_list_push(List_String_Const_u32 *list, List_String_Const_u32 *src_list){ block_zero_array(src_list); } -static void +internal void string_list_push(List_String_Const_Any *list, List_String_Const_Any *src_list){ sll_queue_push_multiple(list->first, list->last, src_list->first, src_list->last); list->node_count += src_list->node_count; @@ -4748,7 +4939,7 @@ string_list_push(List_String_Const_Any *list, List_String_Const_Any *src_list){ block_zero_array(src_list); } -static void +internal void string_list_push_overlap(Arena *arena, List_String_Const_char *list, char overlap, String_Const_char string){ b32 tail_has_overlap = false; b32 string_has_overlap = false; @@ -4773,7 +4964,7 @@ string_list_push_overlap(Arena *arena, List_String_Const_char *list, char overla string_list_push(arena, list, string); } } -static void +internal void string_list_push_overlap(Arena *arena, List_String_Const_u8 *list, u8 overlap, String_Const_u8 string){ b32 tail_has_overlap = false; b32 string_has_overlap = false; @@ -4798,7 +4989,7 @@ string_list_push_overlap(Arena *arena, List_String_Const_u8 *list, u8 overlap, S string_list_push(arena, list, string); } } -static void +internal void string_list_push_overlap(Arena *arena, List_String_Const_u16 *list, u16 overlap, String_Const_u16 string){ b32 tail_has_overlap = false; b32 string_has_overlap = false; @@ -4823,7 +5014,7 @@ string_list_push_overlap(Arena *arena, List_String_Const_u16 *list, u16 overlap, string_list_push(arena, list, string); } } -static void +internal void string_list_push_overlap(Arena *arena, List_String_Const_u32 *list, u32 overlap, String_Const_u32 string){ b32 tail_has_overlap = false; b32 string_has_overlap = false; @@ -4854,7 +5045,7 @@ typedef String_Const_u8 String_u8_Mod_Function_Type(String_Const_u8 string); typedef String_Const_u16 String_u16_Mod_Function_Type(String_Const_u16 string); typedef String_Const_u32 String_u32_Mod_Function_Type(String_Const_u32 string); -static String_Const_char +internal String_Const_char string_list_flatten(Arena *arena, List_String_Const_char list, String_char_Mod_Function_Type *mod, String_Const_char separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ umem term_padding = (rule == StringFill_NullTerminate)?(1):(0);b32 before_first = HasFlag(separator_flags, StringSeparator_BeforeFirst); b32 after_last = HasFlag(separator_flags, StringSeparator_AfterLast); @@ -4881,7 +5072,7 @@ string_list_flatten(Arena *arena, List_String_Const_char list, String_char_Mod_F } return(string.string); } -static String_Const_u8 +internal String_Const_u8 string_list_flatten(Arena *arena, List_String_Const_u8 list, String_u8_Mod_Function_Type *mod, String_Const_u8 separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ umem term_padding = (rule == StringFill_NullTerminate)?(1):(0);b32 before_first = HasFlag(separator_flags, StringSeparator_BeforeFirst); b32 after_last = HasFlag(separator_flags, StringSeparator_AfterLast); @@ -4908,7 +5099,7 @@ string_list_flatten(Arena *arena, List_String_Const_u8 list, String_u8_Mod_Funct } return(string.string); } -static String_Const_u16 +internal String_Const_u16 string_list_flatten(Arena *arena, List_String_Const_u16 list, String_u16_Mod_Function_Type *mod, String_Const_u16 separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ umem term_padding = (rule == StringFill_NullTerminate)?(1):(0);b32 before_first = HasFlag(separator_flags, StringSeparator_BeforeFirst); b32 after_last = HasFlag(separator_flags, StringSeparator_AfterLast); @@ -4935,7 +5126,7 @@ string_list_flatten(Arena *arena, List_String_Const_u16 list, String_u16_Mod_Fun } return(string.string); } -static String_Const_u32 +internal String_Const_u32 string_list_flatten(Arena *arena, List_String_Const_u32 list, String_u32_Mod_Function_Type *mod, String_Const_u32 separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ umem term_padding = (rule == StringFill_NullTerminate)?(1):(0);b32 before_first = HasFlag(separator_flags, StringSeparator_BeforeFirst); b32 after_last = HasFlag(separator_flags, StringSeparator_AfterLast); @@ -4962,72 +5153,72 @@ string_list_flatten(Arena *arena, List_String_Const_u32 list, String_u32_Mod_Fun } return(string.string); } -static String_Const_char +internal String_Const_char string_list_flatten(Arena *arena, List_String_Const_char list, String_Const_char separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ return(string_list_flatten(arena, list, 0, separator, separator_flags, rule)); } -static String_Const_u8 +internal String_Const_u8 string_list_flatten(Arena *arena, List_String_Const_u8 list, String_Const_u8 separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ return(string_list_flatten(arena, list, 0, separator, separator_flags, rule)); } -static String_Const_u16 +internal String_Const_u16 string_list_flatten(Arena *arena, List_String_Const_u16 list, String_Const_u16 separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ return(string_list_flatten(arena, list, 0, separator, separator_flags, rule)); } -static String_Const_u32 +internal String_Const_u32 string_list_flatten(Arena *arena, List_String_Const_u32 list, String_Const_u32 separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ return(string_list_flatten(arena, list, 0, separator, separator_flags, rule)); } -static String_Const_char +internal String_Const_char string_list_flatten(Arena *arena, List_String_Const_char list, String_char_Mod_Function_Type *mod, String_Fill_Terminate_Rule rule){ return(string_list_flatten(arena, list, mod, SCchar(), 0, rule)); } -static String_Const_u8 +internal String_Const_u8 string_list_flatten(Arena *arena, List_String_Const_u8 list, String_u8_Mod_Function_Type *mod, String_Fill_Terminate_Rule rule){ return(string_list_flatten(arena, list, mod, SCu8(), 0, rule)); } -static String_Const_u16 +internal String_Const_u16 string_list_flatten(Arena *arena, List_String_Const_u16 list, String_u16_Mod_Function_Type *mod, String_Fill_Terminate_Rule rule){ return(string_list_flatten(arena, list, mod, SCu16(), 0, rule)); } -static String_Const_u32 +internal String_Const_u32 string_list_flatten(Arena *arena, List_String_Const_u32 list, String_u32_Mod_Function_Type *mod, String_Fill_Terminate_Rule rule){ return(string_list_flatten(arena, list, mod, SCu32(), 0, rule)); } -static String_Const_char +internal String_Const_char string_list_flatten(Arena *arena, List_String_Const_char string, String_Fill_Terminate_Rule rule){ return(string_list_flatten(arena, string, 0, SCchar(), 0, rule)); } -static String_Const_u8 +internal String_Const_u8 string_list_flatten(Arena *arena, List_String_Const_u8 string, String_Fill_Terminate_Rule rule){ return(string_list_flatten(arena, string, 0, SCu8(), 0, rule)); } -static String_Const_u16 +internal String_Const_u16 string_list_flatten(Arena *arena, List_String_Const_u16 string, String_Fill_Terminate_Rule rule){ return(string_list_flatten(arena, string, 0, SCu16(), 0, rule)); } -static String_Const_u32 +internal String_Const_u32 string_list_flatten(Arena *arena, List_String_Const_u32 string, String_Fill_Terminate_Rule rule){ return(string_list_flatten(arena, string, 0, SCu32(), 0, rule)); } -static String_Const_char +internal String_Const_char string_list_flatten(Arena *arena, List_String_Const_char string){ return(string_list_flatten(arena, string, 0, SCchar(), 0, StringFill_NoTerminate)); } -static String_Const_u8 +internal String_Const_u8 string_list_flatten(Arena *arena, List_String_Const_u8 string){ return(string_list_flatten(arena, string, 0, SCu8(), 0, StringFill_NoTerminate)); } -static String_Const_u16 +internal String_Const_u16 string_list_flatten(Arena *arena, List_String_Const_u16 string){ return(string_list_flatten(arena, string, 0, SCu16(), 0, StringFill_NoTerminate)); } -static String_Const_u32 +internal String_Const_u32 string_list_flatten(Arena *arena, List_String_Const_u32 string){ return(string_list_flatten(arena, string, 0, SCu32(), 0, StringFill_NoTerminate)); } -static List_String_Const_char +internal List_String_Const_char string_split(Arena *arena, String_Const_char string, char *split_characters, i32 split_character_count){ List_String_Const_char list = {}; for (;;){ @@ -5048,7 +5239,7 @@ string_split(Arena *arena, String_Const_char string, char *split_characters, i32 } return(list); } -static List_String_Const_u8 +internal List_String_Const_u8 string_split(Arena *arena, String_Const_u8 string, u8 *split_characters, i32 split_character_count){ List_String_Const_u8 list = {}; for (;;){ @@ -5069,7 +5260,7 @@ string_split(Arena *arena, String_Const_u8 string, u8 *split_characters, i32 spl } return(list); } -static List_String_Const_u16 +internal List_String_Const_u16 string_split(Arena *arena, String_Const_u16 string, u16 *split_characters, i32 split_character_count){ List_String_Const_u16 list = {}; for (;;){ @@ -5090,7 +5281,7 @@ string_split(Arena *arena, String_Const_u16 string, u16 *split_characters, i32 s } return(list); } -static List_String_Const_u32 +internal List_String_Const_u32 string_split(Arena *arena, String_Const_u32 string, u32 *split_characters, i32 split_character_count){ List_String_Const_u32 list = {}; for (;;){ @@ -5112,7 +5303,7 @@ string_split(Arena *arena, String_Const_u32 string, u32 *split_characters, i32 s return(list); } -static List_String_Const_char +internal List_String_Const_char string_split_needle(Arena *arena, String_Const_char string, String_Const_char needle){ List_String_Const_char list = {}; for (;string.size > 0;){ @@ -5128,7 +5319,7 @@ string_split_needle(Arena *arena, String_Const_char string, String_Const_char ne } return(list); } -static List_String_Const_u8 +internal List_String_Const_u8 string_split_needle(Arena *arena, String_Const_u8 string, String_Const_u8 needle){ List_String_Const_u8 list = {}; for (;string.size > 0;){ @@ -5144,7 +5335,7 @@ string_split_needle(Arena *arena, String_Const_u8 string, String_Const_u8 needle } return(list); } -static List_String_Const_u16 +internal List_String_Const_u16 string_split_needle(Arena *arena, String_Const_u16 string, String_Const_u16 needle){ List_String_Const_u16 list = {}; for (;string.size > 0;){ @@ -5160,7 +5351,7 @@ string_split_needle(Arena *arena, String_Const_u16 string, String_Const_u16 need } return(list); } -static List_String_Const_u32 +internal List_String_Const_u32 string_split_needle(Arena *arena, String_Const_u32 string, String_Const_u32 needle){ List_String_Const_u32 list = {}; for (;string.size > 0;){ @@ -5177,7 +5368,7 @@ string_split_needle(Arena *arena, String_Const_u32 string, String_Const_u32 need return(list); } -static void +internal void string_list_insert_separators(Arena *arena, List_String_Const_char *list, String_Const_char separator, String_Separator_Flag flags){ Node_String_Const_char *last = list->last; for (Node_String_Const_char *node = list->first, *next = 0; @@ -5209,7 +5400,7 @@ string_list_insert_separators(Arena *arena, List_String_Const_char *list, String list->total_size += separator.size; } } -static void +internal void string_list_insert_separators(Arena *arena, List_String_Const_u8 *list, String_Const_u8 separator, String_Separator_Flag flags){ Node_String_Const_u8 *last = list->last; for (Node_String_Const_u8 *node = list->first, *next = 0; @@ -5241,7 +5432,7 @@ string_list_insert_separators(Arena *arena, List_String_Const_u8 *list, String_C list->total_size += separator.size; } } -static void +internal void string_list_insert_separators(Arena *arena, List_String_Const_u16 *list, String_Const_u16 separator, String_Separator_Flag flags){ Node_String_Const_u16 *last = list->last; for (Node_String_Const_u16 *node = list->first, *next = 0; @@ -5273,7 +5464,7 @@ string_list_insert_separators(Arena *arena, List_String_Const_u16 *list, String_ list->total_size += separator.size; } } -static void +internal void string_list_insert_separators(Arena *arena, List_String_Const_u32 *list, String_Const_u32 separator, String_Separator_Flag flags){ Node_String_Const_u32 *last = list->last; for (Node_String_Const_u32 *node = list->first, *next = 0; @@ -5306,7 +5497,7 @@ string_list_insert_separators(Arena *arena, List_String_Const_u32 *list, String_ } } -static void +internal void string_list_rewrite_nodes(Arena *arena, List_String_Const_char *list, String_Const_char needle, String_Const_char new_value){ for (Node_String_Const_char *node = list->first; node != 0; @@ -5318,7 +5509,7 @@ string_list_rewrite_nodes(Arena *arena, List_String_Const_char *list, String_Con } } } -static void +internal void string_list_rewrite_nodes(Arena *arena, List_String_Const_u8 *list, String_Const_u8 needle, String_Const_u8 new_value){ for (Node_String_Const_u8 *node = list->first; node != 0; @@ -5330,7 +5521,7 @@ string_list_rewrite_nodes(Arena *arena, List_String_Const_u8 *list, String_Const } } } -static void +internal void string_list_rewrite_nodes(Arena *arena, List_String_Const_u16 *list, String_Const_u16 needle, String_Const_u16 new_value){ for (Node_String_Const_u16 *node = list->first; node != 0; @@ -5342,7 +5533,7 @@ string_list_rewrite_nodes(Arena *arena, List_String_Const_u16 *list, String_Cons } } } -static void +internal void string_list_rewrite_nodes(Arena *arena, List_String_Const_u32 *list, String_Const_u32 needle, String_Const_u32 new_value){ for (Node_String_Const_u32 *node = list->first; node != 0; @@ -5355,28 +5546,28 @@ string_list_rewrite_nodes(Arena *arena, List_String_Const_u32 *list, String_Cons } } -static String_Const_char +internal String_Const_char string_condense_whitespace(Arena *arena, String_Const_char string){ char split_characters[] = { ' ', '\t', '\n', '\r', '\f', '\v', }; List_String_Const_char list = string_split(arena, string, split_characters, ArrayCount(split_characters)); string_list_insert_separators(arena, &list, SCchar(split_characters, 1), StringSeparator_NoFlags); return(string_list_flatten(arena, list, StringFill_NullTerminate)); } -static String_Const_u8 +internal String_Const_u8 string_condense_whitespace(Arena *arena, String_Const_u8 string){ u8 split_characters[] = { ' ', '\t', '\n', '\r', '\f', '\v', }; List_String_Const_u8 list = string_split(arena, string, split_characters, ArrayCount(split_characters)); string_list_insert_separators(arena, &list, SCu8(split_characters, 1), StringSeparator_NoFlags); return(string_list_flatten(arena, list, StringFill_NullTerminate)); } -static String_Const_u16 +internal String_Const_u16 string_condense_whitespace(Arena *arena, String_Const_u16 string){ u16 split_characters[] = { ' ', '\t', '\n', '\r', '\f', '\v', }; List_String_Const_u16 list = string_split(arena, string, split_characters, ArrayCount(split_characters)); string_list_insert_separators(arena, &list, SCu16(split_characters, 1), StringSeparator_NoFlags); return(string_list_flatten(arena, list, StringFill_NullTerminate)); } -static String_Const_u32 +internal String_Const_u32 string_condense_whitespace(Arena *arena, String_Const_u32 string){ u32 split_characters[] = { ' ', '\t', '\n', '\r', '\f', '\v', }; List_String_Const_u32 list = string_split(arena, string, split_characters, ArrayCount(split_characters)); @@ -5384,7 +5575,7 @@ string_condense_whitespace(Arena *arena, String_Const_u32 string){ return(string_list_flatten(arena, list, StringFill_NullTerminate)); } -static List_String_Const_u8 +internal List_String_Const_u8 string_split_wildcards(Arena *arena, String_Const_u8 string){ List_String_Const_u8 list = {}; if (string_get_character(string, 0) == '*'){ @@ -5400,7 +5591,7 @@ string_split_wildcards(Arena *arena, String_Const_u8 string){ return(list); } -static b32 +internal b32 string_wildcard_match(List_String_Const_u8 list, String_Const_u8 string, String_Match_Rule rule){ b32 success = true; if (list.node_count > 0){ @@ -5435,16 +5626,16 @@ string_wildcard_match(List_String_Const_u8 list, String_Const_u8 string, String_ return(success); } -static b32 +internal b32 string_wildcard_match(List_String_Const_u8 list, String_Const_u8 string){ return(string_wildcard_match(list, string, StringMatch_Exact)); } -static b32 +internal b32 string_wildcard_match_insensitive(List_String_Const_u8 list, String_Const_u8 string){ return(string_wildcard_match(list, string, StringMatch_CaseInsensitive)); } -static void +internal void string_list_reverse(List_String_Const_char *list){ Node_String_Const_char *first = 0; Node_String_Const_char *last = list->first; @@ -5457,7 +5648,7 @@ string_list_reverse(List_String_Const_char *list){ list->first = first; list->last = last; } -static void +internal void string_list_reverse(List_String_Const_u8 *list){ Node_String_Const_u8 *first = 0; Node_String_Const_u8 *last = list->first; @@ -5470,7 +5661,7 @@ string_list_reverse(List_String_Const_u8 *list){ list->first = first; list->last = last; } -static void +internal void string_list_reverse(List_String_Const_u16 *list){ Node_String_Const_u16 *first = 0; Node_String_Const_u16 *last = list->first; @@ -5483,7 +5674,7 @@ string_list_reverse(List_String_Const_u16 *list){ list->first = first; list->last = last; } -static void +internal void string_list_reverse(List_String_Const_u32 *list){ Node_String_Const_u32 *first = 0; Node_String_Const_u32 *last = list->first; @@ -5503,7 +5694,7 @@ global_const u8 utf8_class[32] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,2,2,2,2,3,3,4,5, }; -static Character_Consume_Result +internal Character_Consume_Result utf8_consume(u8 *str, umem max){ Character_Consume_Result result = {1, max_u32}; u8 byte = str[0]; @@ -5556,7 +5747,7 @@ utf8_consume(u8 *str, umem max){ return(result); } -static Character_Consume_Result +internal Character_Consume_Result utf16_consume(u16 *str, umem max){ Character_Consume_Result result = {1, max_u32}; result.codepoint = str[0]; @@ -5568,7 +5759,7 @@ utf16_consume(u16 *str, umem max){ return(result); } -static u32 +internal u32 utf8_write(u8 *str, u32 codepoint){ u32 inc = 0; if (codepoint <= 0x7F){ @@ -5600,7 +5791,7 @@ utf8_write(u8 *str, u32 codepoint){ return(inc); } -static u32 +internal u32 utf16_write(u16 *str, u32 codepoint){ u32 inc = 1; if (codepoint == max_u32){ @@ -5620,7 +5811,7 @@ utf16_write(u16 *str, u32 codepoint){ //////////////////////////////// -static String_u8 +internal String_u8 string_u8_from_string_char(Arena *arena, String_Const_char string, String_Fill_Terminate_Rule rule){ String_u8 out = {}; out.cap = string.size; @@ -5638,7 +5829,7 @@ string_u8_from_string_char(Arena *arena, String_Const_char string, String_Fill_T return(out); } -static String_u16 +internal String_u16 string_u16_from_string_char(Arena *arena, String_Const_char string, String_Fill_Terminate_Rule rule){ String_u16 out = {}; out.cap = string.size; @@ -5656,7 +5847,7 @@ string_u16_from_string_char(Arena *arena, String_Const_char string, String_Fill_ return(out); } -static String_u32 +internal String_u32 string_u32_from_string_char(Arena *arena, String_Const_char string, String_Fill_Terminate_Rule rule){ String_u32 out = {}; out.cap = string.size; @@ -5674,7 +5865,7 @@ string_u32_from_string_char(Arena *arena, String_Const_char string, String_Fill_ return(out); } -static String_char +internal String_char string_char_from_string_u8(Arena *arena, String_Const_u8 string, String_Fill_Terminate_Rule rule){ String_char out = {}; out.cap = string.size; @@ -5696,7 +5887,7 @@ string_char_from_string_u8(Arena *arena, String_Const_u8 string, String_Fill_Ter return(out); } -static String_u16 +internal String_u16 string_u16_from_string_u8(Arena *arena, String_Const_u8 string, String_Fill_Terminate_Rule rule){ String_u16 out = {}; out.cap = string.size; @@ -5718,7 +5909,7 @@ string_u16_from_string_u8(Arena *arena, String_Const_u8 string, String_Fill_Term return(out); } -static String_u32 +internal String_u32 string_u32_from_string_u8(Arena *arena, String_Const_u8 string, String_Fill_Terminate_Rule rule){ String_u32 out = {}; out.cap = string.size; @@ -5740,7 +5931,7 @@ string_u32_from_string_u8(Arena *arena, String_Const_u8 string, String_Fill_Term return(out); } -static String_char +internal String_char string_char_from_string_u16(Arena *arena, String_Const_u16 string, String_Fill_Terminate_Rule rule){ String_char out = {}; out.cap = string.size; @@ -5762,7 +5953,7 @@ string_char_from_string_u16(Arena *arena, String_Const_u16 string, String_Fill_T return(out); } -static String_u8 +internal String_u8 string_u8_from_string_u16(Arena *arena, String_Const_u16 string, String_Fill_Terminate_Rule rule){ String_u8 out = {}; out.cap = string.size*3; @@ -5784,7 +5975,7 @@ string_u8_from_string_u16(Arena *arena, String_Const_u16 string, String_Fill_Ter return(out); } -static String_u32 +internal String_u32 string_u32_from_string_u16(Arena *arena, String_Const_u16 string, String_Fill_Terminate_Rule rule){ String_u32 out = {}; out.cap = string.size; @@ -5806,7 +5997,7 @@ string_u32_from_string_u16(Arena *arena, String_Const_u16 string, String_Fill_Te return(out); } -static String_char +internal String_char string_char_from_string_u32(Arena *arena, String_Const_u32 string, String_Fill_Terminate_Rule rule){ String_char out = {}; out.cap = string.size; @@ -5826,7 +6017,7 @@ string_char_from_string_u32(Arena *arena, String_Const_u32 string, String_Fill_T return(out); } -static String_u8 +internal String_u8 string_u8_from_string_u32(Arena *arena, String_Const_u32 string, String_Fill_Terminate_Rule rule){ String_u8 out = {}; out.cap = string.size*4; @@ -5845,7 +6036,7 @@ string_u8_from_string_u32(Arena *arena, String_Const_u32 string, String_Fill_Ter return(out); } -static String_u16 +internal String_u16 string_u16_from_string_u32(Arena *arena, String_Const_u32 string, String_Fill_Terminate_Rule rule){ String_u16 out = {}; out.cap = string.size*2; @@ -5866,58 +6057,58 @@ string_u16_from_string_u32(Arena *arena, String_Const_u32 string, String_Fill_Te //////////////////////////////// -static String_char +internal String_char string_char_from_string_u8(Arena *arena, String_Const_u8 string){ return(string_char_from_string_u8(arena, string, StringFill_NoTerminate)); } -static String_char +internal String_char string_char_from_string_u16(Arena *arena, String_Const_u16 string){ return(string_char_from_string_u16(arena, string, StringFill_NoTerminate)); } -static String_char +internal String_char string_char_from_string_u32(Arena *arena, String_Const_u32 string){ return(string_char_from_string_u32(arena, string, StringFill_NoTerminate)); } -static String_u8 +internal String_u8 string_u8_from_string_char(Arena *arena, String_Const_char string){ return(string_u8_from_string_char(arena, string, StringFill_NoTerminate)); } -static String_u8 +internal String_u8 string_u8_from_string_u16(Arena *arena, String_Const_u16 string){ return(string_u8_from_string_u16(arena, string, StringFill_NoTerminate)); } -static String_u8 +internal String_u8 string_u8_from_string_u32(Arena *arena, String_Const_u32 string){ return(string_u8_from_string_u32(arena, string, StringFill_NoTerminate)); } -static String_u16 +internal String_u16 string_u16_from_string_char(Arena *arena, String_Const_char string){ return(string_u16_from_string_char(arena, string, StringFill_NoTerminate)); } -static String_u16 +internal String_u16 string_u16_from_string_u8(Arena *arena, String_Const_u8 string){ return(string_u16_from_string_u8(arena, string, StringFill_NoTerminate)); } -static String_u16 +internal String_u16 string_u16_from_string_u32(Arena *arena, String_Const_u32 string){ return(string_u16_from_string_u32(arena, string, StringFill_NoTerminate)); } -static String_u32 +internal String_u32 string_u32_from_string_char(Arena *arena, String_Const_char string){ return(string_u32_from_string_char(arena, string, StringFill_NoTerminate)); } -static String_u32 +internal String_u32 string_u32_from_string_u8(Arena *arena, String_Const_u8 string){ return(string_u32_from_string_u8(arena, string, StringFill_NoTerminate)); } -static String_u32 +internal String_u32 string_u32_from_string_u16(Arena *arena, String_Const_u16 string){ return(string_u32_from_string_u16(arena, string, StringFill_NoTerminate)); } //////////////////////////////// -static String_Const_char +internal String_Const_char string_char_from_any(Arena *arena, String_Const_Any string){ String_Const_char result = {}; switch (string.encoding){ @@ -5928,7 +6119,7 @@ string_char_from_any(Arena *arena, String_Const_Any string){ } return(result); } -static String_Const_u8 +internal String_Const_u8 string_u8_from_any(Arena *arena, String_Const_Any string){ String_Const_u8 result = {}; switch (string.encoding){ @@ -5939,7 +6130,7 @@ string_u8_from_any(Arena *arena, String_Const_Any string){ } return(result); } -static String_Const_u16 +internal String_Const_u16 string_u16_from_any(Arena *arena, String_Const_Any string){ String_Const_u16 result = {}; switch (string.encoding){ @@ -5950,7 +6141,7 @@ string_u16_from_any(Arena *arena, String_Const_Any string){ } return(result); } -static String_Const_u32 +internal String_Const_u32 string_u32_from_any(Arena *arena, String_Const_Any string){ String_Const_u32 result = {}; switch (string.encoding){ @@ -5962,7 +6153,7 @@ string_u32_from_any(Arena *arena, String_Const_Any string){ return(result); } -static String_Const_Any +internal String_Const_Any string_any_from_any(Arena *arena, String_Encoding encoding, String_Const_Any string){ String_Const_Any result = {encoding}; switch (encoding){ @@ -5974,7 +6165,7 @@ string_any_from_any(Arena *arena, String_Encoding encoding, String_Const_Any str return(result); } -static List_String_Const_char +internal List_String_Const_char string_list_char_from_any(Arena *arena, List_String_Const_Any list){ List_String_Const_char result = {}; for (Node_String_Const_Any *node = list.first; @@ -5984,7 +6175,7 @@ string_list_char_from_any(Arena *arena, List_String_Const_Any list){ } return(result); } -static List_String_Const_u8 +internal List_String_Const_u8 string_list_u8_from_any(Arena *arena, List_String_Const_Any list){ List_String_Const_u8 result = {}; for (Node_String_Const_Any *node = list.first; @@ -5994,7 +6185,7 @@ string_list_u8_from_any(Arena *arena, List_String_Const_Any list){ } return(result); } -static List_String_Const_u16 +internal List_String_Const_u16 string_list_u16_from_any(Arena *arena, List_String_Const_Any list){ List_String_Const_u16 result = {}; for (Node_String_Const_Any *node = list.first; @@ -6004,7 +6195,7 @@ string_list_u16_from_any(Arena *arena, List_String_Const_Any list){ } return(result); } -static List_String_Const_u32 +internal List_String_Const_u32 string_list_u32_from_any(Arena *arena, List_String_Const_Any list){ List_String_Const_u32 result = {}; for (Node_String_Const_Any *node = list.first; @@ -6017,7 +6208,7 @@ string_list_u32_from_any(Arena *arena, List_String_Const_Any list){ //////////////////////////////// -static List_String_Const_char +internal List_String_Const_char string_replace_list(Arena *arena, String_Const_char source, String_Const_char needle, String_Const_char replacement){ List_String_Const_char list = {}; for (;;){ @@ -6033,7 +6224,7 @@ string_replace_list(Arena *arena, String_Const_char source, String_Const_char ne } return(list); } -static List_String_Const_u8 +internal List_String_Const_u8 string_replace_list(Arena *arena, String_Const_u8 source, String_Const_u8 needle, String_Const_u8 replacement){ List_String_Const_u8 list = {}; for (;;){ @@ -6049,7 +6240,7 @@ string_replace_list(Arena *arena, String_Const_u8 source, String_Const_u8 needle } return(list); } -static List_String_Const_u16 +internal List_String_Const_u16 string_replace_list(Arena *arena, String_Const_u16 source, String_Const_u16 needle, String_Const_u16 replacement){ List_String_Const_u16 list = {}; for (;;){ @@ -6065,7 +6256,7 @@ string_replace_list(Arena *arena, String_Const_u16 source, String_Const_u16 need } return(list); } -static List_String_Const_u32 +internal List_String_Const_u32 string_replace_list(Arena *arena, String_Const_u32 source, String_Const_u32 needle, String_Const_u32 replacement){ List_String_Const_u32 list = {}; for (;;){ @@ -6082,52 +6273,52 @@ string_replace_list(Arena *arena, String_Const_u32 source, String_Const_u32 need return(list); } -static String_Const_char +internal String_Const_char string_replace(Arena *arena, String_Const_char source, String_Const_char needle, String_Const_char replacement, String_Fill_Terminate_Rule rule){ List_String_Const_char list = string_replace_list(arena, source, needle, replacement); return(string_list_flatten(arena, list, rule)); } -static String_Const_u8 +internal String_Const_u8 string_replace(Arena *arena, String_Const_u8 source, String_Const_u8 needle, String_Const_u8 replacement, String_Fill_Terminate_Rule rule){ List_String_Const_u8 list = string_replace_list(arena, source, needle, replacement); return(string_list_flatten(arena, list, rule)); } -static String_Const_u16 +internal String_Const_u16 string_replace(Arena *arena, String_Const_u16 source, String_Const_u16 needle, String_Const_u16 replacement, String_Fill_Terminate_Rule rule){ List_String_Const_u16 list = string_replace_list(arena, source, needle, replacement); return(string_list_flatten(arena, list, rule)); } -static String_Const_u32 +internal String_Const_u32 string_replace(Arena *arena, String_Const_u32 source, String_Const_u32 needle, String_Const_u32 replacement, String_Fill_Terminate_Rule rule){ List_String_Const_u32 list = string_replace_list(arena, source, needle, replacement); return(string_list_flatten(arena, list, rule)); } -static String_Const_char +internal String_Const_char string_replace(Arena *arena, String_Const_char source, String_Const_char needle, String_Const_char replacement){ return(string_replace(arena, source, needle, replacement, StringFill_NoTerminate)); } -static String_Const_u8 +internal String_Const_u8 string_replace(Arena *arena, String_Const_u8 source, String_Const_u8 needle, String_Const_u8 replacement){ return(string_replace(arena, source, needle, replacement, StringFill_NoTerminate)); } -static String_Const_u16 +internal String_Const_u16 string_replace(Arena *arena, String_Const_u16 source, String_Const_u16 needle, String_Const_u16 replacement){ return(string_replace(arena, source, needle, replacement, StringFill_NoTerminate)); } -static String_Const_u32 +internal String_Const_u32 string_replace(Arena *arena, String_Const_u32 source, String_Const_u32 needle, String_Const_u32 replacement){ return(string_replace(arena, source, needle, replacement, StringFill_NoTerminate)); } //////////////////////////////// -static b32 +internal b32 byte_is_ascii(u8 byte){ return(byte == '\r' || byte == '\n' || byte == '\t' || (' ' <= byte && byte <= '~')); } -static b32 +internal b32 data_is_ascii(Data data){ u8 *ptr = (u8*)data.data; u8 *one_past_last = ptr + data.size; @@ -6143,7 +6334,7 @@ data_is_ascii(Data data){ //////////////////////////////// -static String_Const_u8 +internal String_Const_u8 string_escape(Arena *arena, String_Const_u8 string){ List_String_Const_u8 list = string_replace_list(arena, string, string_u8_litexpr("\\"), string_u8_litexpr("\\\\")); @@ -6167,7 +6358,7 @@ string_escape(Arena *arena, String_Const_u8 string){ return(string_list_flatten(arena, list, StringFill_NullTerminate)); } -static String_Const_char +internal String_Const_char string_interpret_escapes(Arena *arena, String_Const_char string){ char *space = push_array(arena, char, string.size + 1); String_char result = Schar(space, 0, string.size); @@ -6218,7 +6409,7 @@ string_interpret_escapes(Arena *arena, String_Const_char string){ return(result.string); } -static String_Const_u8 +internal String_Const_u8 string_interpret_escapes(Arena *arena, String_Const_u8 string){ return(SCu8(string_interpret_escapes(arena, SCchar(string)))); } @@ -6258,7 +6449,7 @@ global_const u8 base64_reverse[128] = { 0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0xFF,0xFF,0xFF,0xFF,0xFF, }; -static umem +internal umem digit_count_from_integer(u64 x, u32 radix){ umem result = {}; if (radix >= 2 && radix <= 16){ @@ -6275,7 +6466,7 @@ digit_count_from_integer(u64 x, u32 radix){ return(result); } -static String_Const_u8 +internal String_Const_u8 string_from_integer(Arena *arena, u64 x, u32 radix){ String_Const_u8 result = {}; if (radix >= 2 && radix <= 16){ @@ -6301,7 +6492,7 @@ string_from_integer(Arena *arena, u64 x, u32 radix){ return(result); } -static b32 +internal b32 string_is_integer(String_Const_u8 string, u32 radix){ b32 is_integer = false; if (radix <= 16){ @@ -6323,7 +6514,7 @@ string_is_integer(String_Const_u8 string, u32 radix){ return(is_integer); } -static u64 +internal u64 string_to_integer(String_Const_u8 string, u32 radix){ u64 x = 0; if (radix <= 16){ @@ -6340,12 +6531,12 @@ string_to_integer(String_Const_u8 string, u32 radix){ return(x); } -static u64 +internal u64 string_to_integer(String_Const_char string, u32 radix){ return(string_to_integer(SCu8((u8*)string.str, string.size), radix)); } -static String_Const_u8 +internal String_Const_u8 string_base64_encode_from_binary(Arena *arena, void *data, umem size){ umem char_count = div_round_up_positive(size*8, 6); char_count = round_up_umem(char_count, 4); @@ -6384,7 +6575,7 @@ string_base64_encode_from_binary(Arena *arena, void *data, umem size){ return(string); } -static Data +internal Data data_decode_from_base64(Arena *arena, u8 *str, umem size){ Data data = {}; if (size%4 == 0){ @@ -6429,27 +6620,6 @@ data_decode_from_base64(Arena *arena, u8 *str, umem size){ return(data); } -//////////////////////////////// - -#if defined(FSTRING_GUARD) -static String -string_old_from_new(String_Const_char string){ - return(make_string(string.str, (i32)string.size)); -} -static String -string_old_from_new(String_Const_u8 string){ - return(make_string((char*)string.str, (i32)string.size)); -} -static String_Const_char -string_new_from_old(String string){ - return(SCchar(string.str, (umem)string.size)); -} -static String_Const_u8 -string_new_u8_from_old(String string){ - return(SCu8((u8*)string.str, (umem)string.size)); -} -#endif - #endif // BOTTOM diff --git a/4coder_base_types.h b/4coder_base_types.h index 079bdb83..8044c27f 100644 --- a/4coder_base_types.h +++ b/4coder_base_types.h @@ -1107,6 +1107,34 @@ struct Scratch_Block{ Temp_Memory temp; }; +//////////////////////////////// + +struct Heap_Basic_Node{ + Heap_Basic_Node *next; + Heap_Basic_Node *prev; +}; + +struct Heap_Node{ + union{ + struct{ + Heap_Basic_Node order; + Heap_Basic_Node alloc; + umem size; + }; + u8 force_size__[64]; + }; +}; + +struct Heap{ + Arena arena; + Heap_Basic_Node in_order; + Heap_Basic_Node free_nodes; + umem used_space; + umem total_space; +}; + +//#define DO_HEAP_CHECKS + #endif // BOTTOM diff --git a/4coder_casey_classic.cpp b/4coder_casey_classic.cpp deleted file mode 100644 index 2ae5aed6..00000000 --- a/4coder_casey_classic.cpp +++ /dev/null @@ -1,1950 +0,0 @@ -/* NOTE(casey): This code is _extremely_ bad and is mostly just me hacking things - around to put in features I want in advance of 4coder having them properly. - Most of the time I haven't even taken enough time to read the 4coder API - to know what I'm actually even doing. So if you decide to use the code in - here, be advised that it might be super crashy or break something or cause you - to lose work or who knows what else! - - DON'T SAY I WE DIDN'T WARN YA: This custom extension provided "as is" without - warranty of any kind, either express or implied, including without - limitation any implied warranties of condition, uninterrupted use, - merchantability, fitness for a particular purpose, or non-infringement. -*/ - -/* TODO(casey): Here are our current issues - - - High priority: - - Seems to buggily break out of the search sometimes for no reason? (eg., you hit the end and it just drops out of the search instead of stopping?) - - Tracked this one down: I think it is because spurious mousewheel or other inputs break - out of the search. How can this be prevented? - - Replace: - - Needs to be case-insensitive, or at least have the option to be - - Needs to replace using the case of the thing being replaced, or at least have the option to do so - - Deleting lines in comments is busted right now, probably because of the way I implemented my D command. - This is probably something I need to fix for myself, but it's basically a problem whereby deleting a line - sucks the next line up and indents it weirdly. - - I'd prefer it if file-open deleted per-character instead of deleting entire path sections. Deleting a whole path segment should be a different key, maybe? - - Simimlarly, it'd be nice to get another Emacs behavior in here, which is that if you start a new path name anywhere in the path, it - discards the initial part. This was where you'd have w:/temp/foo/whatever/p:/foo it would just lop off everything before the p:, - similarly in unix you would have w:/temp/foo/whatever//foo it would lop off everything before the /foo. This is to make it so - you don't have to erase the whole current path that comes up just to start typing a new path from scratch. It's nice! - - Real, robust jump-to-function (eg., no crashes and supports filtering by substring like the file picker does) - - - Search: - - Should highlight all matches in the buffer - - - Display: - - Dialogs like query-replace can lead to obscuring the cursor position if it happened to be on the top lines of the display - - When switching _back_ to a buffer, it seems like it loses the scroll position, instead preferring - to center the cursor? This is undesirable IMO... <<< Check this again - - I'd like to be able to hide the mark in text entry mode, and show the whole highlighted - region in edit mode - perhaps even with a magic split at the top or bottom that shows where the mark - is if it's off screen? - - NOTE / IMPORTANT / TODO highlighting? Ability to customize? Whatever. - - Some kind of parentheses highlighting? I can write this myself, but I - would need some way of adding highlight information to the buffer. - - Need a way of highlighting the current line like Emacs does for the benefit - of people on The Stream(TM) - - Some kind of matching brace display so in long ifs, etc., you can see - what they match (maybe draw it directly into the buffer?) - - - Indentation: - - Need to have better indentation / wrapping control for typing in comments. - Right now it's a bit worse than Emacs, which does automatically put you at - the same margin as the prev. line (4coder just goes back to column 1). It'd - be nice if it go _better_ than Emacs, with no need to manually flow comments, - etc. - - - Buffer management: - - I'd like to be able to set a buffer to "auto-revert", so it reloads automatically whenever it changes externally - - If you undo back to where there are no changes, the "buffer changed" flag should be cleared - - - File system - - When switching to a buffer that has changed on disk, notify? Really this can just - be some way to query the modification flag and then the customization layer can do it? - - I'd prefer it if file-open could create new files, and that I could get called on that - so I can insert my boilerplate headers on new files - - - Need auto-complete for things like "arbitrary command", with options listed, etc., - so this should either be built into 4ed, or the custom DLL should have the ability - to display possible completions and iterate over internal cmdid's, etc. Possibly - the latter, for maximal ability of customizers to add their own commands? - - - Macro recording/playback - - - Arbitrary cool features: - - Once you can highlight things in 4coder buffers, I could make it so that my - metacompiler output _ranges_ for errors, so it highlights the whole token rather - than putting the cursor in a spot. - - Highlight on the screen what the completion would be if you hit TAB now (eg., if the string appears elsewhere on the screen) - - LOC count for the buffer and for all buffers summed shown in the title bar? - - Show auto-parsed #if/if/for/while/etc. statements at else and closing places. - - Automatic highlighting of the region in side the parentheses / etc. - - You should just implement a shell inside 4coder which can call all the 4coder - stuff as well as execute system stuff, so that from now on you just write - scripts "in 4coder", etc., so they are always portable everywhere 4coder runs? - - - Things I should write: - - Ability to do "file open from same directory as the current buffer" - - Spell-checker - - Repeat last replace? - - Maybe search could be a permanent thing, so instead of initiating a search, - you're just _changing_ the search term with MODAL-S, and then there's _always_ - a next-of-these-in... and that could go through buffers in order, to... -*/ - -// NOTE(casey): Microsoft/Windows is poopsauce. - -#include -#include -#include -#include - -#include "4coder_default_include.cpp" - -#define internal static - -struct Parsed_Error -{ - int exists; - - String target_file_name; - int target_line_number; - int target_column_number; - - int source_buffer_id; - int source_position; -}; - -static bool GlobalEditMode; -static bool GlobalBrightMode; -static char *GlobalCompilationBufferName = "*compilation*"; - -// TODO(casey): If 4coder gets variables at some point, this would go in a variable. -static char BuildDirectory[4096] = "./"; - -#define ZeroStruct(a) memset(&(a), 0, sizeof(a)) - -enum token_type -{ - Token_Unknown, - - Token_OpenParen, - Token_CloseParen, - Token_Asterisk, - Token_Minus, - Token_Plus, - Token_ForwardSlash, - Token_Percent, - Token_Colon, - Token_Number, - Token_Comma, - - Token_EndOfStream, -}; -struct token -{ - token_type Type; - - size_t TextLength; - char *Text; -}; - -struct tokenizer -{ - char *At; -}; - -internal bool -IsEndOfLine(char C) -{ - bool Result = ((C == '\n') || - (C == '\r')); - - return(Result); -} - -internal bool -IsWhitespace(char C) -{ - bool Result = ((C == ' ') || - (C == '\t') || - (C == '\v') || - (C == '\f') || - IsEndOfLine(C)); - - return(Result); -} - -internal bool -IsAlpha(char C) -{ - bool Result = (((C >= 'a') && (C <= 'z')) || - ((C >= 'A') && (C <= 'Z'))); - - return(Result); -} - -internal bool -IsNumeric(char C) -{ - bool Result = ((C >= '0') && (C <= '9')); - - return(Result); -} - -static void -EatAllWhitespace(tokenizer *Tokenizer) -{ - for(;;) - { - if(IsWhitespace(Tokenizer->At[0])) - { - ++Tokenizer->At; - } - else if((Tokenizer->At[0] == '/') && - (Tokenizer->At[1] == '/')) - { - Tokenizer->At += 2; - while(Tokenizer->At[0] && !IsEndOfLine(Tokenizer->At[0])) - { - ++Tokenizer->At; - } - } - else if((Tokenizer->At[0] == '/') && - (Tokenizer->At[1] == '*')) - { - Tokenizer->At += 2; - while(Tokenizer->At[0] && - !((Tokenizer->At[0] == '*') && - (Tokenizer->At[1] == '/'))) - { - ++Tokenizer->At; - } - - if(Tokenizer->At[0] == '*') - { - Tokenizer->At += 2; - } - } - else - { - break; - } - } -} - -static token -GetToken(tokenizer *Tokenizer) -{ - EatAllWhitespace(Tokenizer); - - token Token = {}; - Token.TextLength = 1; - Token.Text = Tokenizer->At; - char C = Tokenizer->At[0]; - ++Tokenizer->At; - switch(C) - { - case 0: {--Tokenizer->At; Token.Type = Token_EndOfStream;} break; - - case '(': {Token.Type = Token_OpenParen;} break; - case ')': {Token.Type = Token_CloseParen;} break; - case '*': {Token.Type = Token_Asterisk;} break; - case '-': {Token.Type = Token_Minus;} break; - case '+': {Token.Type = Token_Plus;} break; - case '/': {Token.Type = Token_ForwardSlash;} break; - case '%': {Token.Type = Token_Percent;} break; - case ':': {Token.Type = Token_Colon;} break; - case ',': {Token.Type = Token_Comma;} break; - - default: - { - if(IsNumeric(C)) - { - // TODO(casey): Real number - Token.Type = Token_Number; - while(IsNumeric(Tokenizer->At[0]) || - (Tokenizer->At[0] == '.') || - (Tokenizer->At[0] == 'f')) - { - ++Tokenizer->At; - Token.TextLength = Tokenizer->At - Token.Text; - } - } - else - { - Token.Type = Token_Unknown; - } - } break; - } - - return(Token); -} - -static token -PeekToken(tokenizer *Tokenizer) -{ - tokenizer Tokenizer2 = *Tokenizer; - token Result = GetToken(&Tokenizer2); - return(Result); -} - -internal bool -IsH(String extension) -{ - bool Result = (match(extension, make_lit_string("h")) || - match(extension, make_lit_string("hpp")) || - match(extension, make_lit_string("hin"))); - - return(Result); -} - -internal bool -IsCPP(String extension) -{ - bool Result = (match(extension, make_lit_string("c")) || - match(extension, make_lit_string("cpp")) || - match(extension, make_lit_string("cin"))); - - return(Result); -} - -internal bool -IsBee(String extension) -{ - bool Result = (match(extension, make_lit_string("bee")) != 0); - - return(Result); -} - -internal bool -IsShader(String extension) -{ - bool Result = (match(extension, make_lit_string("ps")) || - match(extension, make_lit_string("vs")) || - match(extension, make_lit_string("cs")) || - match(extension, make_lit_string("ts")) || - match(extension, make_lit_string("gs"))); - - return(Result); -} - -internal bool -IsINL(String extension) -{ - bool Result = (match(extension, make_lit_string("inl")) != 0); - - return(Result); -} - -internal bool -IsJavascript(String extension) -{ - bool Result = (match(extension, make_lit_string("js")) != 0); - - return(Result); -} - -internal bool -IsBAT(String extension) -{ - bool Result = (match(extension, make_lit_string("bat")) != 0); - - return(Result); -} - -internal bool -IsTXT(String extension) -{ - bool Result = (match(extension, make_lit_string("txt")) != 0); - - return(Result); -} - -internal bool -IsCMirror(String extension) -{ - bool Result = (match(extension, make_lit_string("cmirror")) != 0); - - return(Result); -} - -internal bool -IsMTD(String extension) -{ - bool Result = (match(extension, make_lit_string("mtd")) != 0); - - return(Result); -} - -internal bool -IsOutline(String extension) -{ - bool Result = (match(extension, make_lit_string("tol")) != 0); - - return(Result); -} - -internal bool -IsMollyWebMarkup(String extension) -{ - bool Result = (match(extension, make_lit_string("mwm")) != 0); - - return(Result); -} - -internal bool -IsCode(String extension) -{ - bool Result = (IsJavascript(extension) || IsBee(extension) || IsH(extension) || IsCPP(extension) || IsINL(extension) || IsBAT(extension) || IsCMirror(extension) || IsShader(extension) || IsMTD(extension)); - - return(Result); -} - -internal bool -IsDoc(String extension) -{ - bool Result = (IsTXT(extension) || IsOutline(extension) || IsMollyWebMarkup(extension)); - - return(Result); -} - -CUSTOM_COMMAND_SIG(casey_open_in_other) -{ - exec_command(app, change_active_panel); - exec_command(app, interactive_open_or_new); -} - -CUSTOM_COMMAND_SIG(casey_clean_and_save) -{ - exec_command(app, clean_all_lines); - exec_command(app, eol_nixify); - exec_command(app, save); -} - -CUSTOM_COMMAND_SIG(casey_newline_and_indent) -{ - // NOTE(allen): The idea here is that if the current buffer is - // read-only, it cannot be edited anyway. So instead let the return - // key indicate an attempt to interpret the line as a location to jump to. - - View_Summary view = get_active_view(app, AccessProtected); - Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected); - - if (buffer.lock_flags & AccessProtected){ - exec_command(app, goto_jump_at_cursor); - } - else{ - exec_command(app, write_character); - exec_command(app, auto_tab_line_at_cursor); - } -} - -CUSTOM_COMMAND_SIG(casey_open_file_other_window) -{ - exec_command(app, change_active_panel); - exec_command(app, interactive_open_or_new); -} - -CUSTOM_COMMAND_SIG(casey_switch_buffer_other_window) -{ - exec_command(app, change_active_panel); - exec_command(app, interactive_switch_buffer); -} - -internal void -DeleteAfterMotion(struct Application_Links *app, Custom_Command_Function *motion) -{ - unsigned int access = AccessOpen; - View_Summary view = get_active_view_DEP(app, access); - - int pos2 = view.cursor.pos; - motion(app); - refresh_view(app, &view); - int pos1 = view.cursor.pos; - - Range range = make_range(pos1, pos2); - - Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - - // NOTE(allen|a4.0.19): This 'paragraph' should fix 85% of whitespace problems, but if - // it has some issue, you can get the old behavior by just removing it. Doing it by - // cursor motion always seemed to introduce other problems spots. - if (range.min > 0 && range.max < buffer.size){ - char before = buffer_get_char(app, &buffer, range.min - 1); - char after = buffer_get_char(app, &buffer, range.max); - - if ((IsWhitespace(before) || before == '(') && IsWhitespace(after)){ - if (after == ' '){ - range.max += 1; - } - else if (before == ' '){ - range.min -= 1; - } - } - } - - buffer_replace_range(app, &buffer, range.min, range.max, 0, 0); -} - -CUSTOM_COMMAND_SIG(casey_delete_token_left) -{ - DeleteAfterMotion(app, seek_white_or_token_left); -} - -CUSTOM_COMMAND_SIG(casey_delete_token_right) -{ - DeleteAfterMotion(app, seek_white_or_token_right); -} - -CUSTOM_COMMAND_SIG(casey_kill_to_end_of_line) -{ - unsigned int access = AccessOpen; - View_Summary view = get_active_view_DEP(app, access); - - int pos2 = view.cursor.pos; - exec_command(app, seek_end_of_line); - refresh_view(app, &view); - int pos1 = view.cursor.pos; - - Range range = make_range(pos1, pos2); - if(pos1 == pos2) - { - range.max += 1; - } - - Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - buffer_replace_range(app, &buffer, range.min, range.max, 0, 0); - exec_command(app, auto_tab_line_at_cursor); -} - -CUSTOM_COMMAND_SIG(casey_paste_and_tab) -{ - exec_command(app, paste); - exec_command(app, auto_tab_range); -} - -CUSTOM_COMMAND_SIG(casey_seek_beginning_of_line_and_tab) -{ - exec_command(app, seek_beginning_of_line); - exec_command(app, auto_tab_line_at_cursor); -} - -CUSTOM_COMMAND_SIG(casey_seek_beginning_of_line) -{ - exec_command(app, auto_tab_line_at_cursor); - exec_command(app, seek_beginning_of_line); -} - -struct switch_to_result -{ - bool Switched; - bool Loaded; - View_Summary view; - Buffer_Summary buffer; -}; - -internal void -SanitizeSlashes(String Value) -{ - for(int At = 0; - At < Value.size; - ++At) - { - if(Value.str[At] == '\\') - { - Value.str[At] = '/'; - } - } -} - -internal switch_to_result -SwitchToOrLoadFile(struct Application_Links *app, String FileName, bool CreateIfNotFound = false) -{ - switch_to_result Result = {}; - - SanitizeSlashes(FileName); - - unsigned int access = AccessAll; - View_Summary view = get_active_view_DEP(app, access); - Buffer_Summary buffer = get_buffer_by_name(app, FileName.str, FileName.size, access); - - Result.view = view; - Result.buffer = buffer; - - if(buffer.exists) - { - view_set_buffer(app, &view, buffer.buffer_id, 0); - Result.Switched = true; - } - else - { - if(file_exists(app, FileName.str, FileName.size) || CreateIfNotFound) - { - // NOTE(allen): This opens the file and puts it in &view - // This returns false if the open fails. - view_open_file(app, &view, expand_str(FileName), false); - - Result.buffer = get_buffer_by_name(app, FileName.str, FileName.size, access); - - Result.Loaded = true; - Result.Switched = true; - } - } - - return(Result); -} - -CUSTOM_COMMAND_SIG(casey_load_todo) -{ - int size = app->memory_size/2; - String dir = make_string(app->memory, 0, size); - String command = make_string((char*)app->memory + size, 0, size); - - append(&dir, BuildDirectory); - for(int At = 0; - At < dir.size; - ++At) - { - if(dir.str[At] == '/') - { - dir.str[At] = '\\'; - } - } - - append(&command, dir); - - if(append(&command, "todo.tol")) - { - SwitchToOrLoadFile(app, command, true); - } -} - -CUSTOM_COMMAND_SIG(casey_build_search) -{ - int keep_going = 1; - int old_size; - // TODO(allen): It's fine to get memory this way for now, eventually - // we should properly suballocating from app->memory. - String dir = make_string(app->memory, 0, app->memory_size); - dir.size = directory_get_hot(app, dir.str, dir.memory_size); - - while (keep_going) - { - old_size = dir.size; - append(&dir, "build.bat"); - - if (file_exists(app, dir.str, dir.size)) - { - dir.size = old_size; - memcpy(BuildDirectory, dir.str, dir.size); - BuildDirectory[dir.size] = 0; - - // TODO(allen): There are ways this could be boiled down - // to one print message which would be better. - print_message(app, literal("Building with: ")); - print_message(app, BuildDirectory, dir.size); - print_message(app, literal("build.bat\n")); - - return; - } - - dir.size = old_size; - - if (directory_cd(app, dir.str, &dir.size, dir.memory_size, literal("..")) == 0) - { - keep_going = 0; - print_message(app, literal("Did not find a build.bat\n")); - } - } -} - -CUSTOM_COMMAND_SIG(casey_find_corresponding_file) -{ - unsigned int access = AccessProtected; - View_Summary view = get_active_view_DEP(app, access); - Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - - String extension = file_extension(make_string(buffer.file_name, buffer.file_name_len)); - if (extension.str) - { - char *HExtensions[] = - { - "hpp", - "hin", - "h", - }; - - char *CExtensions[] = - { - "c", - "cin", - "cpp", - }; - - int ExtensionCount = 0; - char **Extensions = 0; - if(IsH(extension)) - { - ExtensionCount = ArrayCount(CExtensions); - Extensions = CExtensions; - } - else if(IsCPP(extension) || IsINL(extension)) - { - ExtensionCount = ArrayCount(HExtensions); - Extensions = HExtensions; - } - - int MaxExtensionLength = 3; - int Space = (int)(buffer.file_name_len + MaxExtensionLength); - String FileNameStem = make_string(buffer.file_name, (int)(extension.str - buffer.file_name), 0); - String TestFileName = make_string(app->memory, 0, Space); - for(int ExtensionIndex = 0; - ExtensionCount; - ++ExtensionIndex) - { - TestFileName.size = 0; - append(&TestFileName, FileNameStem); - append(&TestFileName, Extensions[ExtensionIndex]); - - if(SwitchToOrLoadFile(app, TestFileName, ((ExtensionIndex + 1) == ExtensionCount)).Switched) - { - break; - } - } - } -} - -CUSTOM_COMMAND_SIG(casey_find_corresponding_file_other_window) -{ - unsigned int access = AccessProtected; - View_Summary old_view = get_active_view_DEP(app, access); - Buffer_Summary buffer = get_buffer(app, old_view.buffer_id, access); - - exec_command(app, change_active_panel); - View_Summary new_view = get_active_view_DEP(app, AccessAll); - view_set_buffer(app, &new_view, buffer.buffer_id, 0); - - // exec_command(app, casey_find_corresponding_file); -} - -CUSTOM_COMMAND_SIG(casey_save_and_make_without_asking) -{ - exec_command(app, change_active_panel); - -#if 0 - Buffer_Summary buffer = {}; - - unsigned int access = AccessAll; - for(buffer = get_buffer_first(app, access); - buffer.exists; - get_buffer_next(app, &buffer, access)) - { - save_buffer(app, &buffer, buffer.file_name, buffer.file_name_len, 0); - } -#endif - save_all_dirty_buffers(app); - - // NOTE(allen): The parameter pushing made it a little easier - // to deal with this particular pattern where two similar strings - // were both used. Now both strings need to exist at the same - // time on the users side. - - int size = app->memory_size/2; - String dir = make_string(app->memory, 0, size); - String command = make_string((char*)app->memory + size, 0, size); - - append(&dir, BuildDirectory); - for(int At = 0; - At < dir.size; - ++At) - { - if(dir.str[At] == '/') - { - dir.str[At] = '\\'; - } - } - - append(&command, dir); - - if(append(&command, "build.bat")) - { - unsigned int access = AccessAll; - View_Summary view = get_active_view_DEP(app, access); - exec_system_command(app, &view, - buffer_identifier(GlobalCompilationBufferName, (int)strlen(GlobalCompilationBufferName)), - dir.str, dir.size, - command.str, command.size, - CLI_OverlapWithConflict|CLI_SendEndSignal); - lock_jump_buffer(GlobalCompilationBufferName, str_size(GlobalCompilationBufferName)); - } - exec_command(app, change_active_panel); - - ZeroStruct(prev_location); -} - -#if 1 -CUSTOM_COMMAND_SIG(casey_goto_previous_error) -{ - goto_prev_error_no_skips(app); -} - -CUSTOM_COMMAND_SIG(casey_goto_next_error) -{ - goto_next_error_no_skips(app); -} -#else -CUSTOM_COMMAND_SIG(casey_goto_previous_error) -{ - seek_error(app, &global_part, true, false, -1); -} - -CUSTOM_COMMAND_SIG(casey_goto_next_error) -{ - seek_error(app, &global_part, true, false, 1); -} -#endif - -CUSTOM_COMMAND_SIG(casey_imenu) -{ - // TODO(casey): Implement! -} - -// -// TODO(casey): Everything below this line probably isn't possible yet -// - -CUSTOM_COMMAND_SIG(casey_call_keyboard_macro) -{ - // TODO(casey): Implement! -} - -CUSTOM_COMMAND_SIG(casey_begin_keyboard_macro_recording) -{ - // TODO(casey): Implement! -} - -CUSTOM_COMMAND_SIG(casey_end_keyboard_macro_recording) -{ - // TODO(casey): Implement! -} - -CUSTOM_COMMAND_SIG(casey_fill_paragraph) -{ - // TODO(casey): Implement! -} - -enum calc_node_type -{ - CalcNode_UnaryMinus, - - CalcNode_Add, - CalcNode_Subtract, - CalcNode_Multiply, - CalcNode_Divide, - CalcNode_Mod, - - CalcNode_Constant, -}; -struct calc_node -{ - calc_node_type Type; - double Value; - calc_node *Left; - calc_node *Right; -}; - -internal double -ExecCalcNode(calc_node *Node) -{ - double Result = 0.0f; - - if(Node) - { - switch(Node->Type) - { - case CalcNode_UnaryMinus: {Result = -ExecCalcNode(Node->Left);} break; - case CalcNode_Add: {Result = ExecCalcNode(Node->Left) + ExecCalcNode(Node->Right);} break; - case CalcNode_Subtract: {Result = ExecCalcNode(Node->Left) - ExecCalcNode(Node->Right);} break; - case CalcNode_Multiply: {Result = ExecCalcNode(Node->Left) * ExecCalcNode(Node->Right);} break; - case CalcNode_Divide: {/*TODO(casey): Guard 0*/Result = ExecCalcNode(Node->Left) / ExecCalcNode(Node->Right);} break; - case CalcNode_Mod: {/*TODO(casey): Guard 0*/Result = fmod(ExecCalcNode(Node->Left), ExecCalcNode(Node->Right));} break; - case CalcNode_Constant: {Result = Node->Value;} break; - default: {Assert(!"AHHHHH!");} - } - } - - return(Result); -} - -internal void -FreeCalcNode(calc_node *Node) -{ - if(Node) - { - FreeCalcNode(Node->Left); - FreeCalcNode(Node->Right); - free(Node); - } -} - -internal calc_node * -AddNode(calc_node_type Type, calc_node *Left = 0, calc_node *Right = 0) -{ - calc_node *Node = (calc_node *)malloc(sizeof(calc_node)); - Node->Type = Type; - Node->Value = 0; - Node->Left = Left; - Node->Right = Right; - return(Node); -} - -internal calc_node * -ParseNumber(tokenizer *Tokenizer) -{ - calc_node *Result = AddNode(CalcNode_Constant); - - token Token = GetToken(Tokenizer); - Result->Value = atof(Token.Text); - - return(Result); -} - -internal calc_node * -ParseConstant(tokenizer *Tokenizer) -{ - calc_node *Result = 0; - - token Token = PeekToken(Tokenizer); - if(Token.Type == Token_Minus) - { - Token = GetToken(Tokenizer); - Result = AddNode(CalcNode_UnaryMinus); - Result->Left = ParseNumber(Tokenizer); - } - else - { - Result = ParseNumber(Tokenizer); - } - - return(Result); -} - -#pragma warning(disable:4456) - -internal calc_node * -ParseMultiplyExpression(tokenizer *Tokenizer) -{ - calc_node *Result = 0; - - token Token = PeekToken(Tokenizer); - if((Token.Type == Token_Minus) || - (Token.Type == Token_Number)) - { - Result = ParseConstant(Tokenizer); - token Token = PeekToken(Tokenizer); - if(Token.Type == Token_ForwardSlash) - { - GetToken(Tokenizer); - Result = AddNode(CalcNode_Divide, Result, ParseNumber(Tokenizer)); - } - else if(Token.Type == Token_Asterisk) - { - GetToken(Tokenizer); - Result = AddNode(CalcNode_Multiply, Result, ParseNumber(Tokenizer)); - } - } - - return(Result); -} - -internal calc_node * -ParseAddExpression(tokenizer *Tokenizer) -{ - calc_node *Result = 0; - - token Token = PeekToken(Tokenizer); - if((Token.Type == Token_Minus) || - (Token.Type == Token_Number)) - { - Result = ParseMultiplyExpression(Tokenizer); - token Token = PeekToken(Tokenizer); - if(Token.Type == Token_Plus) - { - GetToken(Tokenizer); - Result = AddNode(CalcNode_Add, Result, ParseMultiplyExpression(Tokenizer)); - } - else if(Token.Type == Token_Minus) - { - GetToken(Tokenizer); - Result = AddNode(CalcNode_Subtract, Result, ParseMultiplyExpression(Tokenizer)); - } - } - - return(Result); -} - -internal calc_node * -ParseCalc(tokenizer *Tokenizer) -{ - calc_node *Node = ParseAddExpression(Tokenizer); - - return(Node); -} - -CUSTOM_COMMAND_SIG(casey_quick_calc) -{ - unsigned int access = AccessOpen; - View_Summary view = get_active_view_DEP(app, access); - - Range range = get_view_range(&view); - - size_t Size = range.max - range.min; - char *Stuff = (char *)malloc(Size + 1); - Stuff[Size] = 0; - - Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - buffer_read_range(app, &buffer, range.min, range.max, Stuff); - - tokenizer Tokenizer = {Stuff}; - calc_node *CalcTree = ParseCalc(&Tokenizer); - double ComputedValue = ExecCalcNode(CalcTree); - FreeCalcNode(CalcTree); - - char ResultBuffer[256]; - int ResultSize = sprintf(ResultBuffer, "%f", ComputedValue); - - buffer_replace_range(app, &buffer, range.min, range.max, ResultBuffer, ResultSize); - - free(Stuff); -} - -internal char * -GetNextString(char *Dest, int DestSize, char *&At) -{ - char *Result = 0; - - if(*At) - { - Result = Dest; - while((--DestSize > 0) && *At && (*At != '\n')) - { - *Dest++ = *At++; - } - *Dest = 0; - - while(*At && (*At != '\n')) - { - ++At; - } - - while(*At && (*At == '\n')) - { - ++At; - } - } - - return(Result); -} - -internal void -OpenProject(Application_Links *app, char *Contents) -{ - int TotalOpenAttempts = 0; - char *At = Contents; - - if(GetNextString(BuildDirectory, sizeof(BuildDirectory) - 1, At)) - { - size_t BuildDirSize = strlen(BuildDirectory); - if((BuildDirSize) && (BuildDirectory[BuildDirSize - 1] == '\n')) - { - --BuildDirSize; - } - - if((BuildDirSize) && (BuildDirectory[BuildDirSize - 1] != '/')) - { - BuildDirectory[BuildDirSize++] = '/'; - BuildDirectory[BuildDirSize] = 0; - } - } - - char SourceFileDirectoryName[4096]; - char FileDirectoryName[4096]; - while(GetNextString(SourceFileDirectoryName, sizeof(SourceFileDirectoryName) - 1, At)) - { - // NOTE(allen|a3.4.4): Here we get the list of files in this directory. - // Notice that we free_file_list at the end. - String dir = make_string(FileDirectoryName, 0, sizeof(FileDirectoryName)); - append(&dir, SourceFileDirectoryName); - if(dir.size && dir.str[dir.size-1] == '\n') - { - --dir.size; - } - - if(dir.size && dir.str[dir.size-1] != '/') - { - dir.str[dir.size++] = '/'; - } - - File_List list = get_file_list(app, dir.str, dir.size); - int dir_size = dir.size; - - for (int unsigned i = 0; i < list.count; ++i) - { - File_Info *info = list.infos + i; - if (!info->folder) - { - String filename = make_string(info->filename, info->filename_len); - String extension = file_extension(filename); - if (IsCode(extension) || IsDoc(extension)) - { - // NOTE(allen): There's no way in the 4coder API to use relative - // paths at the moment, so everything should be full paths. Which is - // managable. Here simply set the dir string size back to where it - // was originally, so that new appends overwrite old ones. - dir.size = dir_size; - append(&dir, info->filename); - - open_file(app, 0, dir.str, dir.size, true, true); - ++TotalOpenAttempts; - } - } - } - - free_file_list(app, list); - } -} - -internal int -IsCodeLegal(int32_t Codepoint) -{ - int Result = ((Codepoint == '\n') || - (Codepoint == '\t') || - (Codepoint == '\r') || - ((Codepoint >= 32) && - (Codepoint <= 126))); - - return(Result); -} - -CUSTOM_COMMAND_SIG(casey_force_codelegal_characters) -{ - View_Summary view = get_active_view_DEP(app, AccessOpen); - Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); - - int32_t line_count = buffer.line_count; - int32_t edit_max = line_count; - - if (edit_max*(int32_t)sizeof(Buffer_Edit) < app->memory_size){ - Buffer_Edit *edits = (Buffer_Edit*)app->memory; - - char data[1024]; - Stream_Chunk chunk = {}; - - int32_t i = 0; - int32_t last_utf = 0; - int32_t run = 0; - - if (init_stream_chunk(&chunk, app, &buffer, i, data, sizeof(data))){ - Buffer_Edit *edit = edits; - - do - { - for (; i < chunk.end; ++i) - { - if(IsCodeLegal(chunk.data[i])) - { - if(run) - { - edit->str_start = 0; - edit->len = 1; - edit->start = last_utf; - edit->end = i; - ++edit; - - run = false; - } - } - else if(!run) - { - last_utf = i; - - run = true; - } - } - } while(forward_stream_chunk(&chunk)); - - if(run) - { - edit->str_start = 0; - edit->len = 1; - edit->start = last_utf; - edit->end = i; - ++edit; - - run = false; - } - - int32_t edit_count = (int32_t)(edit - edits); - buffer_batch_edit(app, &buffer, " ", 1, edits, edit_count, BatchEdit_PreserveTokens); - } - } -} - -static void -casey_list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buffer, Buffer_Summary *decls_buffer){ - - 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 = {}; - - 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_number(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_DEP(app, AccessAll); - view_set_buffer(app, &view, decls_buffer->buffer_id, 0); - - lock_jump_buffer(decls_buffer->buffer_name, decls_buffer->buffer_name_len); - - end_temp_memory(temp); - } -} - -internal void -ClearDeclsBuffer(Application_Links *app, Buffer_Summary *decls_buffer) -{ - String search_name = make_lit_string("*decls*"); - *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); - } -} - -CUSTOM_COMMAND_SIG(casey_list_all_functions_current_buffer){ - uint32_t access = AccessProtected; - View_Summary view = get_active_view_DEP(app, access); - Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - - Buffer_Summary decls_buffer; - ClearDeclsBuffer(app, &decls_buffer); - casey_list_all_functions(app, &global_part, &buffer, &decls_buffer); -} - -CUSTOM_COMMAND_SIG(casey_list_all_functions_globally){ - uint32_t access = AccessProtected; - - Buffer_Summary decls_buffer; - ClearDeclsBuffer(app, &decls_buffer); - - for (Buffer_Summary buffer_it = get_buffer_first(app, access); - buffer_it.exists; - get_buffer_next(app, &buffer_it, access)) - { - casey_list_all_functions(app, &global_part, &buffer_it, &decls_buffer); - } -} - -internal void -UpdateModalIndicator(Application_Links *app) -{ - int unsigned Background = (GlobalBrightMode ? 0xFFFFFFFF : 0xFF161616); - int unsigned Default = (GlobalBrightMode ? 0xFF000000 : 0xFFA08563); - int unsigned Constant = 0xFF6B8E23; - - Theme_Color normal_colors[] = - { - {Stag_Cursor, 0xFF40FF40}, - {Stag_At_Cursor, 0xFF161616}, - {Stag_Mark, 0xFF808080}, - {Stag_Bar, 0xFFCACACA} - }; - - Theme_Color edit_colors[] = - { - {Stag_Cursor, 0xFFFF0000}, - {Stag_At_Cursor, 0xFF00FFFF}, - {Stag_Mark, 0xFFFF6F1A}, - {Stag_Bar, 0xFFCACACA} - }; - - if (GlobalEditMode) - { - set_theme_colors(app, edit_colors, ArrayCount(edit_colors)); - } - else - { - set_theme_colors(app, normal_colors, ArrayCount(normal_colors)); - } - - Theme_Color common_colors[] = - { - {Stag_Comment, 0xFF7D7D7D}, - {Stag_Keyword, 0xFFCD950C}, - {Stag_Preproc, 0xFFDAB98F}, - {Stag_Include, Constant}, - {Stag_Back, Background}, - {Stag_Margin, Background}, - {Stag_Margin_Hover, Background}, - {Stag_Margin_Active, Background}, - {Stag_List_Item,Background}, - {Stag_List_Item_Hover, 0xFF934420}, - {Stag_List_Item_Active, 0xFF934420}, - {Stag_Default, Default}, - - {Stag_Str_Constant, Constant}, - {Stag_Char_Constant, Constant}, - {Stag_Int_Constant, Constant}, - {Stag_Float_Constant, Constant}, - {Stag_Bool_Constant, Constant}, - }; - set_theme_colors(app, common_colors, ArrayCount(common_colors)); -} - -CUSTOM_COMMAND_SIG(begin_free_typing) -{ - GlobalEditMode = false; - UpdateModalIndicator(app); -} - -CUSTOM_COMMAND_SIG(end_free_typing) -{ - GlobalEditMode = true; - UpdateModalIndicator(app); -} - -CUSTOM_COMMAND_SIG(toggle_bright_mode) -{ - GlobalBrightMode = !GlobalBrightMode; - UpdateModalIndicator(app); -} - -#define DEFINE_FULL_BIMODAL_KEY(binding_name,edit_code,normal_code) \ -CUSTOM_COMMAND_SIG(binding_name) \ -{ \ - if(GlobalEditMode) \ - { \ - edit_code; \ - } \ - else \ - { \ - normal_code; \ - } \ -} - -#define DEFINE_BIMODAL_KEY(binding_name,edit_code,normal_code) DEFINE_FULL_BIMODAL_KEY(binding_name,exec_command(app,edit_code),exec_command(app,normal_code)) -#define DEFINE_MODAL_KEY(binding_name,edit_code) DEFINE_BIMODAL_KEY(binding_name,edit_code,write_character) - -// paste_next ? -// cmdid_history_backward, -// cmdid_history_forward, -// toggle_line_wrap, - -DEFINE_MODAL_KEY(modal_space, set_mark); -DEFINE_MODAL_KEY(modal_back_slash, casey_clean_and_save); -DEFINE_MODAL_KEY(modal_single_quote, casey_call_keyboard_macro); -DEFINE_MODAL_KEY(modal_comma, move_down_to_blank_line); -DEFINE_MODAL_KEY(modal_period, casey_fill_paragraph); -DEFINE_MODAL_KEY(modal_forward_slash, change_active_panel); -DEFINE_MODAL_KEY(modal_semicolon, seek_white_or_token_right); -DEFINE_BIMODAL_KEY(modal_open_bracket, casey_begin_keyboard_macro_recording, write_and_auto_tab); -DEFINE_BIMODAL_KEY(modal_close_bracket, casey_end_keyboard_macro_recording, write_and_auto_tab); -DEFINE_MODAL_KEY(modal_a, write_character); // TODO(casey): Arbitrary command + casey_quick_calc -DEFINE_MODAL_KEY(modal_b, interactive_switch_buffer); -DEFINE_MODAL_KEY(modal_c, casey_find_corresponding_file); -DEFINE_MODAL_KEY(modal_d, casey_kill_to_end_of_line); -DEFINE_MODAL_KEY(modal_e, write_character); -DEFINE_MODAL_KEY(modal_f, casey_paste_and_tab); -DEFINE_MODAL_KEY(modal_g, goto_line); -DEFINE_MODAL_KEY(modal_h, seek_white_or_token_left); -DEFINE_MODAL_KEY(modal_i, move_up); -DEFINE_MODAL_KEY(modal_j, casey_list_all_functions_globally); -DEFINE_MODAL_KEY(modal_k, list_all_locations); -DEFINE_MODAL_KEY(modal_l, list_all_substring_locations_case_insensitive); -DEFINE_MODAL_KEY(modal_m, casey_save_and_make_without_asking); -DEFINE_MODAL_KEY(modal_n, goto_next_error); -DEFINE_MODAL_KEY(modal_o, query_replace); -DEFINE_MODAL_KEY(modal_p, replace_in_range); -DEFINE_MODAL_KEY(modal_q, copy); -DEFINE_MODAL_KEY(modal_r, reverse_search); -DEFINE_MODAL_KEY(modal_s, search); -DEFINE_MODAL_KEY(modal_t, casey_load_todo); -DEFINE_MODAL_KEY(modal_u, cmdid_undo); -DEFINE_MODAL_KEY(modal_v, casey_switch_buffer_other_window); -DEFINE_MODAL_KEY(modal_w, cut); -DEFINE_MODAL_KEY(modal_x, casey_find_corresponding_file_other_window); -DEFINE_MODAL_KEY(modal_y, redo); -DEFINE_MODAL_KEY(modal_z, interactive_open_or_new); - -DEFINE_MODAL_KEY(modal_1, casey_build_search); // TODO(casey): Shouldn't need to bind a key for this? -DEFINE_MODAL_KEY(modal_2, write_character); // TODO(casey): Available -DEFINE_MODAL_KEY(modal_3, write_character); // TODO(casey): Available -DEFINE_MODAL_KEY(modal_4, write_character); // TODO(casey): Available -DEFINE_MODAL_KEY(modal_5, toggle_bright_mode); // TODO(casey): Available -DEFINE_MODAL_KEY(modal_6, auto_tab_range); // TODO(casey): Available -DEFINE_MODAL_KEY(modal_7, write_character); // TODO(casey): Available -DEFINE_MODAL_KEY(modal_8, move_up_to_blank_line); // TODO(casey): Available -DEFINE_MODAL_KEY(modal_9, write_character); // TODO(casey): Available -DEFINE_MODAL_KEY(modal_0, kill_buffer); -DEFINE_MODAL_KEY(modal_minus, write_character); // TODO(casey): Available -DEFINE_MODAL_KEY(modal_equals, command_lister); // TODO(allen): Available - -DEFINE_BIMODAL_KEY(modal_backspace, casey_delete_token_left, backspace_char); -DEFINE_BIMODAL_KEY(modal_up, move_up, move_up); -DEFINE_BIMODAL_KEY(modal_down, move_down, move_down); -DEFINE_BIMODAL_KEY(modal_left, seek_white_or_token_left, move_left); -DEFINE_BIMODAL_KEY(modal_right, seek_white_or_token_right, move_right); -DEFINE_BIMODAL_KEY(modal_delete, casey_delete_token_right, delete_char); -DEFINE_BIMODAL_KEY(modal_home, casey_seek_beginning_of_line, casey_seek_beginning_of_line_and_tab); -DEFINE_BIMODAL_KEY(modal_end, seek_end_of_line, seek_end_of_line); -DEFINE_BIMODAL_KEY(modal_page_up, page_up, move_up_to_blank_line); -DEFINE_BIMODAL_KEY(modal_page_down, page_down, move_down_to_blank_line); -DEFINE_BIMODAL_KEY(modal_tab, word_complete, word_complete); - -OPEN_FILE_HOOK_SIG(casey_file_settings) -{ - // NOTE(allen|a4): As of alpha 4 hooks can have parameters which are - // received through functions like this get_parameter_buffer. - // This is different from the past where this hook got a buffer - // from get_active_buffer. - unsigned int access = AccessAll; - //Buffer_Summary buffer = get_parameter_buffer(app, 0, access); - Buffer_Summary buffer = get_buffer(app, buffer_id, access); - - int treat_as_code = 0; - int treat_as_project = 0; - int treat_as_doc = 0; - int treat_as_outline = 0; - int wrap_lines = 1; - int WrapPosition = 1200; - - if (buffer.file_name && buffer.size < (16 << 20)) - { - String ext = file_extension(make_string(buffer.file_name, buffer.file_name_len)); - treat_as_code = IsCode(ext); - treat_as_project = match(ext, make_lit_string("prj")); - treat_as_doc = IsDoc(ext); - treat_as_outline = IsOutline(ext); - } - - if(treat_as_outline) - { - buffer_set_setting(app, &buffer, BufferSetting_VirtualWhitespace, 1); - buffer_set_setting(app, &buffer, BufferSetting_LexWithoutStrings, 1); - } - else if(treat_as_code) - { - buffer_set_setting(app, &buffer, BufferSetting_Lex, treat_as_code); - buffer_set_setting(app, &buffer, BufferSetting_WrapLine, 0); - } - else if(treat_as_doc) - { - buffer_set_setting(app, &buffer, BufferSetting_WrapIndicator, WrapIndicator_Hide); - buffer_set_setting(app, &buffer, BufferSetting_WrapLine, 1); - WrapPosition = 600; - } - else - { - buffer_set_setting(app, &buffer, BufferSetting_WrapLine, wrap_lines); - } - - buffer_set_setting(app, &buffer, BufferSetting_MapID, mapid_file); - buffer_set_setting(app, &buffer, BufferSetting_WrapPosition, WrapPosition); - - if(treat_as_project) - { - int size = buffer.size; - char *ParsingRegion = (char *)malloc(size + 1); - buffer_read_range(app, &buffer, 0, size, ParsingRegion); - ParsingRegion[size] = 0; - OpenProject(app, ParsingRegion); - free(ParsingRegion); - } - - return(0); -} - -bool -CubicUpdateFixedDuration1(float *P0, float *V0, float P1, float V1, float Duration, float dt) -{ - bool Result = false; - - if(dt > 0) - { - if(Duration < dt) - { - *P0 = P1 + (dt - Duration)*V1; - *V0 = V1; - Result = true; - } - else - { - float t = (dt / Duration); - float u = (1.0f - t); - - float C0 = 1*u*u*u; - float C1 = 3*u*u*t; - float C2 = 3*u*t*t; - float C3 = 1*t*t*t; - - float dC0 = -3*u*u; - float dC1 = -6*u*t + 3*u*u; - float dC2 = 6*u*t - 3*t*t; - float dC3 = 3*t*t; - - float B0 = *P0; - float B1 = *P0 + (Duration / 3.0f) * *V0; - float B2 = P1 - (Duration / 3.0f) * V1; - float B3 = P1; - - *P0 = C0*B0 + C1*B1 + C2*B2 + C3*B3; - *V0 = (dC0*B0 + dC1*B1 + dC2*B2 + dC3*B3) * (1.0f / Duration); - } - } - - return(Result); -} - -struct Casey_Scroll_Velocity -{ - float x, y, t; -}; - -Casey_Scroll_Velocity casey_scroll_velocity_[16] = {}; -Casey_Scroll_Velocity *casey_scroll_velocity = casey_scroll_velocity_ - 1; - -SCROLL_RULE_SIG(casey_smooth_scroll_rule){ - Casey_Scroll_Velocity *velocity = casey_scroll_velocity + view_id; - int result = 0; - if(is_new_target) - { - if((*scroll_x != target_x) || - (*scroll_y != target_y)) - { - velocity->t = 0.1f; - } - } - - if(velocity->t > 0) - { - result = !(CubicUpdateFixedDuration1(scroll_x, &velocity->x, target_x, 0.0f, velocity->t, dt) || - CubicUpdateFixedDuration1(scroll_y, &velocity->y, target_y, 0.0f, velocity->t, dt)); - } - - velocity->t -= dt; - if(velocity->t < 0) - { - velocity->t = 0; - *scroll_x = target_x; - *scroll_y = target_y; - } - - return(result); -} - -START_HOOK_SIG(casey_start) -{ - bool HandmadeHeroMachine = (strcmp(getenv("COMPUTERNAME"), "CASEYMPC2") == 0); - - default_4coder_initialize(app); - - exec_command(app, hide_scrollbar); - if(!HandmadeHeroMachine) {exec_command(app, hide_filebar);} - exec_command(app, open_panel_vsplit); - exec_command(app, hide_scrollbar); - if(!HandmadeHeroMachine) {exec_command(app, hide_filebar);} - exec_command(app, change_active_panel); - - change_theme(app, literal("Handmade Hero")); - set_global_face_by_name(app, literal("Droid Sans Mono"), true); - UpdateModalIndicator(app); - - return(0); -} - -extern "C" GET_BINDING_DATA(get_bindings) -{ - Bind_Helper context_actual = begin_bind_helper(data, size); - Bind_Helper *context = &context_actual; - - set_start_hook(context, casey_start); - set_command_caller(context, default_command_caller); - set_render_caller(context, default_render_caller); - set_open_file_hook(context, casey_file_settings); - set_scroll_rule(context, casey_smooth_scroll_rule); - set_end_file_hook(context, end_file_close_jump_list); - - begin_map(context, mapid_global); - { - bind(context, 'z', MDFR_NONE, interactive_open_or_new); - bind(context, 'x', MDFR_NONE, casey_open_in_other); - bind(context, 't', MDFR_NONE, casey_load_todo); - bind(context, '/', MDFR_NONE, change_active_panel); - bind(context, 'b', MDFR_NONE, interactive_switch_buffer); - bind(context, key_page_up, MDFR_NONE, search); - bind(context, key_page_down, MDFR_NONE, reverse_search); - bind(context, 'm', MDFR_NONE, casey_save_and_make_without_asking); - - // NOTE(allen): Added this so mouse would keep working rougly as before. - // Of course now there could be a modal click behavior if that will be useful. - // As well as right click. - bind(context, key_mouse_left, MDFR_NONE, click_set_cursor); - } - end_map(context); - - begin_map(context, mapid_file); - - bind_vanilla_keys(context, write_character); - - // TODO(casey): How can I bind something to just pressing the control key by itself? - // bind(context, key_control, MDFR_NONE, end_free_typing); - - bind(context, key_insert, MDFR_NONE, begin_free_typing); - bind(context, '`', MDFR_NONE, begin_free_typing); - bind(context, key_esc, MDFR_NONE, end_free_typing); - bind(context, '\n', MDFR_NONE, casey_newline_and_indent); - bind(context, '\n', MDFR_SHIFT, casey_newline_and_indent); - - // NOTE(casey): Modal keys come here. - bind(context, ' ', MDFR_NONE, modal_space); - bind(context, ' ', MDFR_SHIFT, modal_space); - - bind(context, '\\', MDFR_NONE, modal_back_slash); - bind(context, '\'', MDFR_NONE, modal_single_quote); - bind(context, ',', MDFR_NONE, modal_comma); - bind(context, '.', MDFR_NONE, modal_period); - bind(context, '/', MDFR_NONE, modal_forward_slash); - bind(context, ';', MDFR_NONE, modal_semicolon); - bind(context, '[', MDFR_NONE, modal_open_bracket); - bind(context, ']', MDFR_NONE, modal_close_bracket); - bind(context, '{', MDFR_NONE, write_and_auto_tab); - bind(context, '}', MDFR_NONE, write_and_auto_tab); - bind(context, 'a', MDFR_NONE, modal_a); - bind(context, 'b', MDFR_NONE, modal_b); - bind(context, 'c', MDFR_NONE, modal_c); - bind(context, 'd', MDFR_NONE, modal_d); - bind(context, 'e', MDFR_NONE, modal_e); - bind(context, 'f', MDFR_NONE, modal_f); - bind(context, 'g', MDFR_NONE, modal_g); - bind(context, 'h', MDFR_NONE, modal_h); - bind(context, 'i', MDFR_NONE, modal_i); - bind(context, 'j', MDFR_NONE, modal_j); - bind(context, 'k', MDFR_NONE, modal_k); - bind(context, 'l', MDFR_NONE, modal_l); - bind(context, 'm', MDFR_NONE, modal_m); - bind(context, 'n', MDFR_NONE, modal_n); - bind(context, 'o', MDFR_NONE, modal_o); - bind(context, 'p', MDFR_NONE, modal_p); - bind(context, 'q', MDFR_NONE, modal_q); - bind(context, 'r', MDFR_NONE, modal_r); - bind(context, 's', MDFR_NONE, modal_s); - bind(context, 't', MDFR_NONE, modal_t); - bind(context, 'u', MDFR_NONE, modal_u); - bind(context, 'v', MDFR_NONE, modal_v); - bind(context, 'w', MDFR_NONE, modal_w); - bind(context, 'x', MDFR_NONE, modal_x); - bind(context, 'y', MDFR_NONE, modal_y); - bind(context, 'z', MDFR_NONE, modal_z); - - bind(context, '1', MDFR_NONE, modal_1); - bind(context, '2', MDFR_NONE, modal_2); - bind(context, '3', MDFR_NONE, modal_3); - bind(context, '4', MDFR_NONE, modal_4); - bind(context, '5', MDFR_NONE, modal_5); - bind(context, '6', MDFR_NONE, modal_6); - bind(context, '7', MDFR_NONE, modal_7); - bind(context, '8', MDFR_NONE, modal_8); - bind(context, '9', MDFR_NONE, modal_9); - bind(context, '0', MDFR_NONE, modal_0); - bind(context, '-', MDFR_NONE, modal_minus); - bind(context, '=', MDFR_NONE, modal_equals); - - bind(context, key_back, MDFR_NONE, modal_backspace); - bind(context, key_back, MDFR_SHIFT, modal_backspace); - - bind(context, key_up, MDFR_NONE, modal_up); - bind(context, key_up, MDFR_SHIFT, modal_up); - - bind(context, key_down, MDFR_NONE, modal_down); - bind(context, key_down, MDFR_SHIFT, modal_down); - - bind(context, key_left, MDFR_NONE, modal_left); - bind(context, key_left, MDFR_SHIFT, modal_left); - - bind(context, key_right, MDFR_NONE, modal_right); - bind(context, key_right, MDFR_SHIFT, modal_right); - - bind(context, key_del, MDFR_NONE, modal_delete); - bind(context, key_del, MDFR_SHIFT, modal_delete); - - bind(context, key_home, MDFR_NONE, modal_home); - bind(context, key_home, MDFR_SHIFT, modal_home); - - bind(context, key_end, MDFR_NONE, modal_end); - bind(context, key_end, MDFR_SHIFT, modal_end); - - bind(context, key_page_up, MDFR_NONE, modal_page_up); - bind(context, key_page_up, MDFR_SHIFT, modal_page_up); - - bind(context, key_page_down, MDFR_NONE, modal_page_down); - bind(context, key_page_down, MDFR_SHIFT, modal_page_down); - - bind(context, '\t', MDFR_NONE, modal_tab); - bind(context, '\t', MDFR_SHIFT, modal_tab); - - bind(context, key_f4, MDFR_ALT, exit_4coder); - - end_map(context); - - begin_map(context, default_lister_ui_map); - bind_vanilla_keys(context, lister__write_character); - bind(context, key_esc, MDFR_NONE, lister__quit); - bind(context, '\n', MDFR_NONE, lister__activate); - bind(context, '\t', MDFR_NONE, lister__activate); - bind(context, key_back, MDFR_NONE, lister__backspace_text_field); - bind(context, key_up, MDFR_NONE, lister__move_up); - bind(context, key_page_up, MDFR_NONE, lister__move_up); - bind(context, key_down, MDFR_NONE, lister__move_down); - bind(context, key_page_down, MDFR_NONE, lister__move_down); - bind(context, key_mouse_wheel, MDFR_NONE, lister__wheel_scroll); - bind(context, key_mouse_left, MDFR_NONE, lister__mouse_press); - bind(context, key_mouse_left_release, MDFR_NONE, lister__mouse_release); - bind(context, key_mouse_move, MDFR_NONE, lister__repaint); - bind(context, key_animate, MDFR_NONE, lister__repaint); - end_map(context); - - end_bind_helper(context); - return context->write_total; -} diff --git a/4coder_clipboard.cpp b/4coder_clipboard.cpp index a5fc2d8d..ee650891 100644 --- a/4coder_clipboard.cpp +++ b/4coder_clipboard.cpp @@ -45,13 +45,14 @@ CUSTOM_DOC("At the cursor, insert the text at the top of the clipboard.") if_view_has_highlighted_range_delete_range(app, view); Managed_Scope scope = view_get_managed_scope(app, view); - managed_variable_set(app, scope, view_next_rewrite_loc, RewritePaste); - i32 paste_index = 0; - managed_variable_set(app, scope, view_paste_index_loc, paste_index); + Rewrite_Type *rewrite = scope_attachment(app, scope, view_next_rewrite_loc, Rewrite_Type); + *rewrite = Rewrite_Paste; + i32 *paste_index = scope_attachment(app, scope, view_paste_index_loc, i32); + *paste_index = 0; Scratch_Block scratch(app); - String_Const_u8 string = push_clipboard_index(app, scratch, 0, paste_index); + String_Const_u8 string = push_clipboard_index(app, scratch, 0, *paste_index); if (string.size > 0){ Buffer_ID buffer = view_get_buffer(app, view, AccessOpen); @@ -80,14 +81,13 @@ CUSTOM_DOC("If the previous command was paste or paste_next, replaces the paste Managed_Scope scope = view_get_managed_scope(app, view); no_mark_snap_to_cursor(app, scope); - u64 rewrite = 0; - managed_variable_get(app, scope, view_rewrite_loc, &rewrite); - if (rewrite == RewritePaste){ - managed_variable_set(app, scope, view_next_rewrite_loc, RewritePaste); - u64 prev_paste_index = 0; - managed_variable_get(app, scope, view_paste_index_loc, &prev_paste_index); - i32 paste_index = (i32)prev_paste_index + 1; - managed_variable_set(app, scope, view_paste_index_loc, paste_index); + Rewrite_Type *rewrite = scope_attachment(app, scope, view_next_rewrite_loc, Rewrite_Type); + if (*rewrite == Rewrite_Paste){ + Rewrite_Type *next_rewrite = scope_attachment(app, scope, view_next_rewrite_loc, Rewrite_Type); + *next_rewrite = Rewrite_Paste; + i32 *paste_index_ptr = scope_attachment(app, scope, view_paste_index_loc, i32); + i32 paste_index = (*paste_index_ptr) + 1; + *paste_index_ptr = paste_index; String_Const_u8 string = push_clipboard_index(app, scratch, 0, paste_index); diff --git a/4coder_config.cpp b/4coder_config.cpp index 7b0332c6..d8239f63 100644 --- a/4coder_config.cpp +++ b/4coder_config.cpp @@ -72,8 +72,8 @@ config_stringize_errors(Arena *arena, Config *parsed){ static void config_parser__advance_to_next(Config_Parser *ctx){ - Cpp_Token *t = ctx->token; - Cpp_Token *e = ctx->end; + Token *t = ctx->token; + Token *e = ctx->end; for (t += 1; t < e && t->type == CPP_TOKEN_COMMENT; t += 1); ctx->token = t; } @@ -1147,8 +1147,8 @@ text_data_to_token_array(Arena *arena, String_Const_u8 data){ b32 success = false; Temp_Memory restore_point = begin_temp(arena); Cpp_Token_Array array = {}; - i32 max_count = (1 << 20)/sizeof(Cpp_Token); - array.tokens = push_array(arena, Cpp_Token, max_count); + i32 max_count = (1 << 20)/sizeof(Token); + array.tokens = push_array(arena, Token, max_count); array.max_count = max_count; Cpp_Keyword_Table kw_table = {}; Cpp_Keyword_Table pp_table = {}; @@ -1518,7 +1518,6 @@ load_config_and_apply(Application_Links *app, Arena *out_arena, Config_Data *con do_matching_enclosure_highlight = config->use_scope_highlight; do_matching_paren_highlight = config->use_paren_helper; do_colored_comment_keywords = config->use_comment_keyword; - adjust_all_buffer_wrap_widths(app, config->default_wrap_width, config->default_min_base_width); global_set_setting(app, GlobalSetting_LAltLCtrlIsAltGr, config->lalt_lctrl_is_altgr); //change_theme(app, config->default_theme_name.str, config->default_theme_name.size); diff --git a/4coder_config.h b/4coder_config.h index cf82b743..938a73f4 100644 --- a/4coder_config.h +++ b/4coder_config.h @@ -31,9 +31,9 @@ struct Config_Error_List{ }; struct Config_Parser{ - Cpp_Token *start; - Cpp_Token *token; - Cpp_Token *end; + Token *start; + Token *token; + Token *end; String_Const_u8 file_name; String_Const_u8 data; diff --git a/4coder_default_framework.cpp b/4coder_default_framework.cpp index e3a64fcd..36c95a63 100644 --- a/4coder_default_framework.cpp +++ b/4coder_default_framework.cpp @@ -68,15 +68,15 @@ new_view_settings(Application_Links *app, View_ID view){ static void view_set_passive(Application_Links *app, View_ID view_id, b32 value){ Managed_Scope scope = view_get_managed_scope(app, view_id); - managed_variable_set(app, scope, view_is_passive_loc, (u64)value); + b32 *is_passive = scope_attachment(app, scope, view_is_passive_loc, b32); + *is_passive = value; } static b32 view_get_is_passive(Application_Links *app, View_ID view_id){ Managed_Scope scope = view_get_managed_scope(app, view_id); - u64 is_passive = 0; - managed_variable_get(app, scope, view_is_passive_loc, &is_passive); - return(is_passive != 0); + b32 *is_passive = scope_attachment(app, scope, view_is_passive_loc, b32); + return(*is_passive); } static View_ID @@ -267,7 +267,9 @@ create_or_switch_to_buffer_and_clear_by_name(Application_Links *app, String_Cons search_buffer = create_buffer(app, name_string, BufferCreate_AlwaysNew); buffer_set_setting(app, search_buffer, BufferSetting_Unimportant, true); buffer_set_setting(app, search_buffer, BufferSetting_ReadOnly, true); +#if 0 buffer_set_setting(app, search_buffer, BufferSetting_WrapLine, false); +#endif view_set_buffer(app, default_target_view, search_buffer, 0); view_set_active(app, default_target_view); } @@ -361,10 +363,8 @@ CUSTOM_DOC("Switch to a named key binding map.") static void default_4coder_initialize(Application_Links *app, char **command_line_files, i32 file_count, i32 override_font_size, b32 override_hinting){ - i32 heap_size = (4 << 20); - void *heap_mem = memory_allocate(app, heap_size); - heap_init(&global_heap); - heap_extend(&global_heap, heap_mem, heap_size); + Base_Allocator *allocator = context_get_base_allocator(app); + heap_init(&global_heap, allocator); #define M \ "Welcome to " VERSION "\n" \ @@ -382,17 +382,17 @@ default_4coder_initialize(Application_Links *app, char **command_line_files, i32 global_config_arena = make_arena_app_links(app); load_config_and_apply(app, &global_config_arena, &global_config, override_font_size, override_hinting); - view_rewrite_loc = managed_variable_create_or_get_id(app, "DEFAULT.rewrite" , 0); - view_next_rewrite_loc = managed_variable_create_or_get_id(app, "DEFAULT.next_rewrite" , 0); - view_paste_index_loc = managed_variable_create_or_get_id(app, "DEFAULT.paste_index" , 0); - view_is_passive_loc = managed_variable_create_or_get_id(app, "DEFAULT.is_passive" , 0); - view_snap_mark_to_cursor = managed_variable_create_or_get_id(app, "DEFAULT.mark_to_cursor", 0); - view_ui_data = managed_variable_create_or_get_id(app, "DEFAULT.ui_data" , 0); - view_highlight_range = managed_variable_create_or_get_id(app, "DEFAULT.highlight" , 0); - view_highlight_buffer = managed_variable_create_or_get_id(app, "DEFAULT.highlight_buf" , 0); - view_render_hook = managed_variable_create_or_get_id(app, "DEFAULT.render" , 0); - - sticky_jump_marker_handle = managed_variable_create_or_get_id(app, "DEFAULT.sticky_jump_marker_handle", 0); + view_rewrite_loc = managed_id_declare(app, SCu8("DEFAULT.rewrite" )); + view_next_rewrite_loc = managed_id_declare(app, SCu8("DEFAULT.next_rewrite" )); + view_paste_index_loc = managed_id_declare(app, SCu8("DEFAULT.paste_index" )); + view_is_passive_loc = managed_id_declare(app, SCu8("DEFAULT.is_passive" )); + view_snap_mark_to_cursor = managed_id_declare(app, SCu8("DEFAULT.mark_to_cursor")); + view_ui_data = managed_id_declare(app, SCu8("DEFAULT.ui_data" )); + view_highlight_range = managed_id_declare(app, SCu8("DEFAULT.highlight" )); + view_highlight_buffer = managed_id_declare(app, SCu8("DEFAULT.highlight_buf" )); + view_render_hook = managed_id_declare(app, SCu8("DEFAULT.render" )); + sticky_jump_marker_handle = managed_id_declare(app, SCu8("DEFAULT.sticky_jump_marker_handle")); + attachment_tokens = managed_id_declare(app, SCu8("DEFAULT.tokens")); // open command line files Arena *scratch = context_get_arena(app); diff --git a/4coder_default_framework.h b/4coder_default_framework.h index bbab5886..bbe66b2a 100644 --- a/4coder_default_framework.h +++ b/4coder_default_framework.h @@ -16,10 +16,11 @@ enum Default_Maps{ //////////////////////////////// -enum Rewrite_Type{ - RewriteNone, - RewritePaste, - RewriteWordComplete +typedef i64 Rewrite_Type; +enum{ + Rewrite_None, + Rewrite_Paste, + Rewrite_WordComplete }; //////////////////////////////// diff --git a/4coder_default_framework_variables.cpp b/4coder_default_framework_variables.cpp index 5789989c..b34744ec 100644 --- a/4coder_default_framework_variables.cpp +++ b/4coder_default_framework_variables.cpp @@ -34,17 +34,19 @@ global String_Const_u8 locked_buffer = {}; global View_ID build_footer_panel_view_id = 0; -global Managed_Variable_ID view_rewrite_loc = 0; -global Managed_Variable_ID view_next_rewrite_loc = 0; -global Managed_Variable_ID view_paste_index_loc = 0; -global Managed_Variable_ID view_is_passive_loc = 0; -global Managed_Variable_ID view_snap_mark_to_cursor = 0; -global Managed_Variable_ID view_ui_data = 0; -global Managed_Variable_ID view_highlight_range = 0; -global Managed_Variable_ID view_highlight_buffer = 0; -global Managed_Variable_ID view_render_hook = 0; +global Managed_ID view_rewrite_loc = 0; +global Managed_ID view_next_rewrite_loc = 0; +global Managed_ID view_paste_index_loc = 0; +global Managed_ID view_is_passive_loc = 0; +global Managed_ID view_snap_mark_to_cursor = 0; +global Managed_ID view_ui_data = 0; +global Managed_ID view_highlight_range = 0; +global Managed_ID view_highlight_buffer = 0; +global Managed_ID view_render_hook = 0; -global Managed_Variable_ID sticky_jump_marker_handle = 0; +global Managed_ID sticky_jump_marker_handle = 0; + +global Managed_ID attachment_tokens = 0; global u8 out_buffer_space[1024]; global u8 command_space[1024]; @@ -61,6 +63,7 @@ global b32 cursor_is_hidden = false; global b32 show_fps_hud = false; +// TODO(allen): REMOVE THIS! global Heap global_heap; enum{ diff --git a/4coder_default_hooks.cpp b/4coder_default_hooks.cpp index 1c2b8235..31651cce 100644 --- a/4coder_default_hooks.cpp +++ b/4coder_default_hooks.cpp @@ -80,29 +80,32 @@ START_HOOK_SIG(default_start){ COMMAND_CALLER_HOOK(default_command_caller){ View_ID view = get_active_view(app, AccessAll); Managed_Scope scope = view_get_managed_scope(app, view); - managed_variable_set(app, scope, view_next_rewrite_loc, 0); + Rewrite_Type *next_rewrite = scope_attachment(app, scope, view_next_rewrite_loc, Rewrite_Type); + *next_rewrite = Rewrite_None; if (fcoder_mode == FCoderMode_NotepadLike){ for (View_ID view_it = get_view_next(app, 0, AccessAll); view_it != 0; view_it = get_view_next(app, view_it, AccessAll)){ Managed_Scope scope_it = view_get_managed_scope(app, view_it); - managed_variable_set(app, scope_it, view_snap_mark_to_cursor, true); + b32 *snap_mark_to_cursor = scope_attachment(app, scope_it, view_snap_mark_to_cursor, b32); + *snap_mark_to_cursor = true; } } cmd.command(app); - u64 next_rewrite = 0; - managed_variable_get(app, scope, view_next_rewrite_loc, &next_rewrite); - managed_variable_set(app, scope, view_rewrite_loc, next_rewrite); - if (fcoder_mode == FCoderMode_NotepadLike){ - for (View_ID view_it = get_view_next(app, 0, AccessAll); - view_it != 0; - view_it = get_view_next(app, view_it, AccessAll)){ - Managed_Scope scope_it = view_get_managed_scope(app, view_it); - u64 val = 0; - if (managed_variable_get(app, scope_it, view_snap_mark_to_cursor, &val)){ - if (val != 0){ + + next_rewrite = scope_attachment(app, scope, view_next_rewrite_loc, Rewrite_Type); + if (next_rewrite != 0){ + Rewrite_Type *rewrite = scope_attachment(app, scope, view_rewrite_loc, Rewrite_Type); + *rewrite = *next_rewrite; + if (fcoder_mode == FCoderMode_NotepadLike){ + for (View_ID view_it = get_view_next(app, 0, AccessAll); + view_it != 0; + view_it = get_view_next(app, view_it, AccessAll)){ + Managed_Scope scope_it = view_get_managed_scope(app, view_it); + b32 *snap_mark_to_cursor = scope_attachment(app, scope_it, view_snap_mark_to_cursor, b32); + if (*snap_mark_to_cursor){ i64 pos = view_get_cursor_pos(app, view_it); view_set_mark(app, view_it, seek_pos(pos)); } @@ -172,6 +175,7 @@ internal void draw_enclosures(Application_Links *app, Text_Layout_ID text_layout_id, Buffer_ID buffer, i64 pos, u32 flags, Range_Highlight_Kind kind, int_color *back_colors, int_color *fore_colors, i32 color_count){ +#if 0 Scratch_Block scratch(app); Range_i64_Array ranges = get_enclosure_ranges(app, scratch, buffer, pos, flags); @@ -225,6 +229,7 @@ draw_enclosures(Application_Links *app, Text_Layout_ID text_layout_id, Buffer_ID color_index += 1; color_index = (color_index%color_count); } +#endif } static argb_color default_colors[Stag_COUNT] = {}; @@ -418,19 +423,18 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View scopes[0] = buffer_get_managed_scope(app, compilation_buffer); scopes[1] = buffer_get_managed_scope(app, buffer); Managed_Scope scope = get_managed_scope_with_multiple_dependencies(app, scopes, ArrayCount(scopes)); - Managed_Object markers_object = 0; - if (managed_variable_get(app, scope, sticky_jump_marker_handle, &markers_object)){ - Temp_Memory temp = begin_temp(scratch); - i32 count = managed_object_get_item_count(app, markers_object); - Marker *markers = push_array(scratch, Marker, count); - managed_object_load_data(app, markers_object, 0, count, markers); - for (i32 i = 0; i < count; i += 1){ - i64 line_number = get_line_number_from_pos(app, buffer, markers[i].pos); - draw_line_highlight(app, text_layout_id, line_number, - Stag_Highlight_Junk); - } - end_temp(temp); + Managed_Object *markers_object = scope_attachment(app, scope, sticky_jump_marker_handle, Managed_Object); + + Temp_Memory temp = begin_temp(scratch); + i32 count = managed_object_get_item_count(app, *markers_object); + Marker *markers = push_array(scratch, Marker, count); + managed_object_load_data(app, *markers_object, 0, count, markers); + for (i32 i = 0; i < count; i += 1){ + i64 line_number = get_line_number_from_pos(app, buffer, markers[i].pos); + draw_line_highlight(app, text_layout_id, line_number, + Stag_Highlight_Junk); } + end_temp(temp); } } @@ -465,20 +469,17 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View b32 has_highlight_range = false; { Managed_Scope scope = view_get_managed_scope(app, view_id); - u64 highlight_buffer = 0; - managed_variable_get(app, scope, view_highlight_buffer, &highlight_buffer); - if (highlight_buffer != 0){ - if ((Buffer_ID)highlight_buffer != buffer){ + Buffer_ID *highlight_buffer = scope_attachment(app, scope, view_highlight_buffer, Buffer_ID); + if (*highlight_buffer != 0){ + if (*highlight_buffer != buffer){ view_disable_highlight_range(app, view_id); } else{ has_highlight_range = true; - Managed_Object highlight = 0; - managed_variable_get(app, scope, view_highlight_range, &highlight); + Managed_Object *highlight = scope_attachment(app, scope, view_highlight_range, Managed_Object); Marker marker_range[2]; - if (managed_object_load_data(app, highlight, 0, 2, marker_range)){ - Range_i64 range = Ii64(marker_range[0].pos, - marker_range[1].pos); + if (managed_object_load_data(app, *highlight, 0, 2, marker_range)){ + Range_i64 range = Ii64(marker_range[0].pos, marker_range[1].pos); draw_character_block(app, text_layout_id, range, Stag_Highlight); paint_text_color(app, text_layout_id, range, Stag_At_Highlight); } @@ -788,26 +789,20 @@ default_render_view(Application_Links *app, Frame_Info frame_info, View_ID view, draw_coordinate_center_push(app, inner.p0); Managed_Scope scope = view_get_managed_scope(app, view); - u64 render_hook_value = 0; - if (managed_variable_get(app, scope, view_render_hook, &render_hook_value)){ - if (render_hook_value == 0){ - if (view_is_in_ui_mode(app, view)){ - default_ui_render_caller(app, view); - } - else{ - default_buffer_render_caller(app, frame_info, view, inner); - } + View_Render_Hook **hook_ptr = scope_attachment(app, scope, view_render_hook, View_Render_Hook*); + + if (*hook_ptr == 0){ + if (view_is_in_ui_mode(app, view)){ + default_ui_render_caller(app, view); } else{ - // TODO(allen): This doesn't actually work. - // We aren't supposed to assume that a function - // pointer is 64-bits I don't think. How - // should we attach a user named hook to a scope - // easily? - View_Render_Hook *hook = (View_Render_Hook*)render_hook_value; - hook(app, view, frame_info, inner); + default_buffer_render_caller(app, frame_info, view, inner); } } + else{ + View_Render_Hook *hook = *hook_ptr; + hook(app, view, frame_info, inner); + } draw_clip_pop(app); draw_coordinate_center_pop(app); @@ -848,30 +843,9 @@ HOOK_SIG(default_exit){ return(result); } -// TODO(allen): how to deal with multiple sizes on a single view -// TODO(allen): expected character advance. HOOK_SIG(default_view_adjust){ - for (View_ID view = get_view_next(app, 0, AccessAll); - view != 0; - view = get_view_next(app, view, AccessAll)){ - Buffer_ID buffer = view_get_buffer(app, view, AccessAll); - - Rect_f32 screen_rect = view_get_screen_rect(app, view); - f32 view_width = rect_width(screen_rect); - - Face_ID face_id = get_face_id(app, buffer); - f32 em = get_string_advance(app, face_id, string_u8_litexpr("m")); - - f32 wrap_width = view_width - 2.0f*em; - f32 min_width = 40.0f*em; - if (wrap_width < min_width){ - wrap_width = min_width; - } - - f32 min_base_width = 20.0f*em; - buffer_set_setting(app, buffer, BufferSetting_WrapPosition, (i32)(wrap_width)); - buffer_set_setting(app, buffer, BufferSetting_MinimumBaseWrapPosition, (i32)(min_base_width)); - } + // NOTE(allen): Called whenever the view layout/sizes have been modified, including + // by full window resize. return(0); } @@ -986,25 +960,32 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){ } } -OPEN_FILE_HOOK_SIG(default_file_settings){ +BUFFER_HOOK_SIG(default_file_settings){ b32 treat_as_code = false; - b32 treat_as_todo = false; b32 lex_without_strings = false; + (void)(lex_without_strings); String_Const_u8_Array extensions = global_config.code_exts; - Parse_Context_ID parse_context_id = 0; - Arena *scratch = context_get_arena(app); Temp_Memory temp = begin_temp(scratch); String_Const_u8 file_name = push_buffer_file_name(app, scratch, buffer_id); - i32 buffer_size = (i32)buffer_get_size(app, buffer_id); - if (file_name.size > 0 && buffer_size < MB(32)){ + if (file_name.size > 0){ String_Const_u8 ext = string_file_extension(file_name); for (i32 i = 0; i < extensions.count; ++i){ if (string_match(ext, extensions.strings[i])){ + + if (string_match(ext, string_u8_litexpr("cpp")) || + string_match(ext, string_u8_litexpr("h")) || + string_match(ext, string_u8_litexpr("c")) || + string_match(ext, string_u8_litexpr("hpp")) || + string_match(ext, string_u8_litexpr("cc"))){ + treat_as_code = true; + } + +#if 0 treat_as_code = true; if (string_match(ext, string_u8_litexpr("cs"))){ @@ -1055,15 +1036,11 @@ OPEN_FILE_HOOK_SIG(default_file_settings){ } parse_context_id = parse_context_language_cpp; } +#endif break; } } - - if (!treat_as_code){ - treat_as_todo = string_match_insensitive(string_front_of_path(file_name), - string_u8_litexpr("todo.txt")); - } } i32 map_id = (treat_as_code)?((i32)default_code_map):((i32)mapid_file); @@ -1073,24 +1050,23 @@ OPEN_FILE_HOOK_SIG(default_file_settings){ buffer_get_setting(app, buffer_id, BufferSetting_MapID, &map_id_query); Assert(map_id_query == default_lister_ui_map); + // TODO(allen): kill all concepts of wrap width as settings +#if 0 buffer_set_setting(app, buffer_id, BufferSetting_WrapPosition, global_config.default_wrap_width); buffer_set_setting(app, buffer_id, BufferSetting_MinimumBaseWrapPosition, global_config.default_min_base_width); +#endif buffer_set_setting(app, buffer_id, BufferSetting_MapID, map_id); buffer_get_setting(app, buffer_id, BufferSetting_MapID, &map_id_query); Assert(map_id_query == map_id); +#if 0 buffer_set_setting(app, buffer_id, BufferSetting_ParserContext, parse_context_id); +#endif // NOTE(allen): Decide buffer settings b32 wrap_lines = true; b32 use_virtual_whitespace = false; b32 use_lexer = false; - if (treat_as_todo){ - lex_without_strings = true; - wrap_lines = true; - use_virtual_whitespace = true; - use_lexer = true; - } - else if (treat_as_code){ + if (treat_as_code){ wrap_lines = global_config.enable_code_wrapping; use_virtual_whitespace = global_config.enable_virtual_whitespace; use_lexer = true; @@ -1100,11 +1076,21 @@ OPEN_FILE_HOOK_SIG(default_file_settings){ if (string_match(buffer_name, string_u8_litexpr("*compilation*"))){ wrap_lines = false; } - if (buffer_size >= (1 << 20)){ - wrap_lines = false; - use_virtual_whitespace = false; + + if (use_lexer){ + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 contents = push_whole_buffer(app, scratch, buffer_id); + Managed_Scope scope = buffer_get_managed_scope(app, buffer_id); + Base_Allocator *allocator = managed_scope_allocator(app, scope); + Token_Array tokens = lex_cpp_initial(allocator, contents); + + Token_Array *tokens_ptr = scope_attachment(app, scope, attachment_tokens, Token_Array); + block_copy_struct(tokens_ptr, &tokens); + + end_temp(temp); } +#if 0 // NOTE(allen|a4.0.12): There is a little bit of grossness going on here. // If we set BufferSetting_Lex to true, it will launch a lexing job. // If a lexing job is active when we set BufferSetting_VirtualWhitespace, the call can fail. @@ -1115,6 +1101,7 @@ OPEN_FILE_HOOK_SIG(default_file_settings){ buffer_set_setting(app, buffer_id, BufferSetting_WrapLine, wrap_lines); buffer_set_setting(app, buffer_id, BufferSetting_VirtualWhitespace, use_virtual_whitespace); buffer_set_setting(app, buffer_id, BufferSetting_Lex, use_lexer); +#endif end_temp(temp); @@ -1122,13 +1109,13 @@ OPEN_FILE_HOOK_SIG(default_file_settings){ return(0); } -OPEN_FILE_HOOK_SIG(default_new_file){ +BUFFER_HOOK_SIG(default_new_file){ // no meaning for return // buffer_id return(0); } -OPEN_FILE_HOOK_SIG(default_file_save){ +BUFFER_HOOK_SIG(default_file_save){ b32 is_virtual = false; if (global_config.automatically_indent_text_on_save && buffer_get_setting(app, buffer_id, BufferSetting_VirtualWhitespace, &is_virtual)){ @@ -1167,7 +1154,7 @@ FILE_EXTERNALLY_MODIFIED_SIG(default_file_externally_modified){ return(0); } -OPEN_FILE_HOOK_SIG(default_end_file){ +BUFFER_HOOK_SIG(default_end_file){ Scratch_Block scratch(app); String_Const_u8 buffer_name = push_buffer_unique_name(app, scratch, buffer_id); String_Const_u8 str = push_u8_stringf(scratch, "Ending file: %s\n", buffer_name.str); diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 97e5f035..18bd0ecf 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -15,10 +15,6 @@ #include "4coder_stringf.cpp" #include "4coder_app_links_allocator.cpp" -#include "4coder_lib/4coder_heap.cpp" - -#define FSTRING_IMPLEMENTATION -#include "4coder_lib/4coder_string.h" #include "4coder_lib/4coder_utf8.h" #include "4coder_lib/4cpp_lexer.h" #include "4coder_table.h" diff --git a/4coder_experiments.cpp b/4coder_experiments.cpp index 4a43ebcc..45e2d54b 100644 --- a/4coder_experiments.cpp +++ b/4coder_experiments.cpp @@ -22,14 +22,13 @@ CUSTOM_COMMAND_SIG(multi_paste){ View_ID view = get_active_view(app, AccessOpen); Managed_Scope scope = view_get_managed_scope(app, view); - u64 rewrite = 0; - managed_variable_get(app, scope, view_rewrite_loc, &rewrite); - if (rewrite == RewritePaste){ - managed_variable_set(app, scope, view_next_rewrite_loc, RewritePaste); - u64 prev_paste_index = 0; - managed_variable_get(app, scope, view_paste_index_loc, &prev_paste_index); - i32 paste_index = (i32)prev_paste_index + 1; - managed_variable_set(app, scope, view_paste_index_loc, paste_index); + Rewrite_Type *rewrite = scope_attachment(app, scope, view_rewrite_loc, Rewrite_Type); + if (*rewrite == Rewrite_Paste){ + Rewrite_Type *next_rewrite = scope_attachment(app, scope, view_next_rewrite_loc, Rewrite_Type); + *next_rewrite = Rewrite_Paste; + i32 *paste_index_ptr = scope_attachment(app, scope, view_paste_index_loc, i32); + i32 paste_index = (*paste_index_ptr) + 1; + *paste_index_ptr = paste_index; String_Const_u8 string = push_clipboard_index(app, scratch, 0, paste_index); @@ -41,7 +40,6 @@ CUSTOM_COMMAND_SIG(multi_paste){ view_set_mark(app, view, seek_pos(range.max + 1)); view_set_cursor_and_preferred_x(app, view, seek_pos(range.max + insert_string.size)); - // TODO(allen): Send this to all views. Theme_Color paste = {}; paste.tag = Stag_Paste; get_theme_colors(app, &paste, 1); @@ -202,15 +200,15 @@ CUSTOM_DOC("If the cursor is found to be on the name of a function parameter in if (get_token_from_pos(app, buffer, cursor_pos, &result)){ if (!result.in_whitespace_after_token){ static const i32 stream_space_size = 512; - Cpp_Token stream_space[stream_space_size]; + Token stream_space[stream_space_size]; Stream_Tokens_DEP stream = {}; if (init_stream_tokens(&stream, app, buffer, result.token_index, stream_space, stream_space_size)){ i32 token_index = result.token_index; - Cpp_Token token = stream.tokens[token_index]; + Token token = stream.tokens[token_index]; if (token.type == CPP_TOKEN_IDENTIFIER){ - Cpp_Token original_token = token; + Token original_token = token; String_Const_u8 old_lexeme = push_token_lexeme(app, scratch, buffer, token); i32 proc_body_found = 0; @@ -219,7 +217,7 @@ CUSTOM_DOC("If the cursor is found to be on the name of a function parameter in ++token_index; do{ for (; token_index < stream.end; ++token_index){ - Cpp_Token *token_ptr = stream.tokens + token_index; + Token *token_ptr = stream.tokens + token_index; switch (token_ptr->type){ case CPP_TOKEN_BRACE_OPEN: { @@ -271,7 +269,7 @@ CUSTOM_DOC("If the cursor is found to be on the name of a function parameter in still_looping = 0; do{ for (; token_index < stream.end; ++token_index){ - Cpp_Token *token_ptr = stream.tokens + token_index; + Token *token_ptr = stream.tokens + token_index; switch (token_ptr->type){ case CPP_TOKEN_IDENTIFIER: { @@ -349,12 +347,12 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu Cpp_Get_Token_Result result = {}; if (get_token_from_pos(app, buffer, pos, &result)){ if (!result.in_whitespace_after_token){ - Cpp_Token stream_space[32]; + Token stream_space[32]; Stream_Tokens_DEP stream = {}; if (init_stream_tokens(&stream, app, buffer, result.token_index, stream_space, 32)){ i32 token_index = result.token_index; - Cpp_Token token = stream.tokens[token_index]; + Token token = stream.tokens[token_index]; if (token.type == CPP_TOKEN_BRACE_OPEN){ ++token_index; @@ -366,7 +364,7 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu b32 still_looping = false; do{ for (; seeker_index < stream.end; ++seeker_index){ - Cpp_Token *token_seeker = stream.tokens + seeker_index; + Token *token_seeker = stream.tokens + seeker_index; switch (token_seeker->type){ case CPP_TOKEN_BRACE_CLOSE: closed_correctly = true; @@ -398,7 +396,7 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu do{ for (;token_index < stream.end; ++token_index){ - Cpp_Token *token_ptr = stream.tokens + token_index; + Token *token_ptr = stream.tokens + token_index; switch (token_ptr->type){ case CPP_TOKEN_IDENTIFIER: { diff --git a/4coder_file.h b/4coder_file.h index 431290cf..09197291 100644 --- a/4coder_file.h +++ b/4coder_file.h @@ -8,8 +8,6 @@ #define FCODER_FILE_ENUMERATOR_CPP #include "4coder_base_types.h" -#define FSTRING_IMPLEMENTATION -#include "4coder_lib/4coder_string.h" #include #include diff --git a/4coder_function_list.cpp b/4coder_function_list.cpp index 8d54cabb..d4065964 100644 --- a/4coder_function_list.cpp +++ b/4coder_function_list.cpp @@ -14,6 +14,8 @@ static Get_Positions_Results get_function_positions(Application_Links *app, Buffer_ID buffer, i32 first_token_index, Function_Positions *positions_array, i32 positions_max){ Get_Positions_Results result = {}; + NotImplemented; +#if 0 Token_Range token_range = buffer_get_token_range(app, buffer); if (token_range.first != 0){ Token_Iterator token_it = make_token_iterator(token_range, first_token_index); @@ -21,7 +23,7 @@ get_function_positions(Application_Links *app, Buffer_ID buffer, i32 first_token i32 nest_level = 0; i32 paren_nest_level = 0; - Cpp_Token *first_paren = 0; + Token *first_paren = 0; i32 first_paren_index = 0; i32 first_paren_position = 0; i32 last_paren_index = 0; @@ -33,7 +35,7 @@ get_function_positions(Application_Links *app, Buffer_ID buffer, i32 first_token first_paren_index = 0; first_paren_position = 0; last_paren_index = 0; - for (Cpp_Token *token = token_iterator_current(&token_it); + for (Token *token = token_iterator_current(&token_it); token != 0; token = token_iterator_goto_next(&token_it)){ if (!(token->flags & CPP_TFLAG_PP_BODY)){ @@ -67,7 +69,7 @@ get_function_positions(Application_Links *app, Buffer_ID buffer, i32 first_token // Look for a closing parenthese to mark the end of a function signature. paren_mode1: paren_nest_level = 0; - for (Cpp_Token *token = token_iterator_current(&token_it); + for (Token *token = token_iterator_current(&token_it); token != 0; token = token_iterator_goto_next(&token_it)){ if (!(token->flags & CPP_TFLAG_PP_BODY)){ @@ -93,11 +95,11 @@ get_function_positions(Application_Links *app, Buffer_ID buffer, i32 first_token // Look backwards from an open parenthese to find the start of a function signature. paren_mode2: { - Cpp_Token *restore_point = token_iterator_current(&token_it); + Token *restore_point = token_iterator_current(&token_it); token_iterator_set(&token_it, first_paren); i32 signature_start_index = 0; - for (Cpp_Token *token = token_iterator_current(&token_it); + for (Token *token = token_iterator_current(&token_it); token != 0; token = token_iterator_goto_prev(&token_it)){ if ((token->flags & CPP_TFLAG_PP_BODY) || (token->flags & CPP_TFLAG_PP_DIRECTIVE) || @@ -136,12 +138,15 @@ get_function_positions(Application_Links *app, Buffer_ID buffer, i32 first_token end:; } +#endif return(result); } static void print_positions_buffered(Application_Links *app, Buffer_Insertion *out, Buffer_ID buffer, Function_Positions *positions_array, i32 positions_count){ + NotImplemented; +#if 0 Arena *scratch = context_get_arena(app); Temp_Memory temp = begin_temp(scratch); @@ -161,9 +166,9 @@ print_positions_buffered(Application_Links *app, Buffer_Insertion *out, Buffer_I if (token_range.first != 0){ insertf(out, "%.*s:%lld: ", string_expand(buffer_name), line_number); - Cpp_Token prev_token = {}; + Token prev_token = {}; Token_Iterator token_it = make_token_iterator(token_range, start_index); - for (Cpp_Token *token = token_iterator_current(&token_it); + for (Token *token = token_iterator_current(&token_it); token != 0 && token_iterator_current_index(&token_it) <= end_index; token = token_iterator_goto_next_raw(&token_it)){ if ((token->flags & CPP_TFLAG_PP_BODY) == 0 && token->type != CPP_TOKEN_COMMENT){ @@ -194,10 +199,14 @@ print_positions_buffered(Application_Links *app, Buffer_Insertion *out, Buffer_I } end_temp(temp); +#endif } static void list_all_functions(Application_Links *app, Buffer_ID optional_target_buffer){ + + NotImplemented; +#if 0 // TODO(allen): Use create or switch to buffer and clear here? String_Const_u8 decls_name = string_u8_litexpr("*decls*"); Buffer_ID decls_buffer = get_buffer_by_name(app, decls_name, AccessAll); @@ -260,6 +269,7 @@ list_all_functions(Application_Links *app, Buffer_ID optional_target_buffer){ lock_jump_buffer(app, decls_name); end_temp(temp); +#endif } diff --git a/4coder_generated/app_functions.h b/4coder_generated/app_functions.h index 32548702..619c6b9c 100644 --- a/4coder_generated/app_functions.h +++ b/4coder_generated/app_functions.h @@ -12,7 +12,6 @@ struct Application_Links; #define CLIPBOARD_POST_SIG(n) b32 n(Application_Links *app, i32 clipboard_id, String_Const_u8 string) #define CLIPBOARD_COUNT_SIG(n) i32 n(Application_Links *app, i32 clipboard_id) #define PUSH_CLIPBOARD_INDEX_SIG(n) String_Const_u8 n(Application_Links *app, Arena *arena, i32 clipboard_id, i32 item_index) -#define CREATE_PARSE_CONTEXT_SIG(n) Parse_Context_ID n(Application_Links *app, Parser_String_And_Type *kw, u32 kw_count, Parser_String_And_Type *pp, u32 pp_count) #define GET_BUFFER_COUNT_SIG(n) i32 n(Application_Links *app) #define GET_BUFFER_NEXT_SIG(n) Buffer_ID n(Application_Links *app, Buffer_ID buffer_id, Access_Flag access) #define GET_BUFFER_BY_NAME_SIG(n) Buffer_ID n(Application_Links *app, String_Const_u8 name, Access_Flag access) @@ -44,11 +43,9 @@ struct Application_Links; #define PUSH_BUFFER_FILE_NAME_SIG(n) String_Const_u8 n(Application_Links *app, Arena *arena, Buffer_ID buffer_id) #define BUFFER_GET_DIRTY_STATE_SIG(n) Dirty_State n(Application_Links *app, Buffer_ID buffer_id) #define BUFFER_SET_DIRTY_STATE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Dirty_State dirty_state) -#define BUFFER_TOKENS_ARE_READY_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id) #define BUFFER_GET_SETTING_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_ID setting, i32 *value_out) #define BUFFER_SET_SETTING_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_ID setting, i32 value) #define BUFFER_GET_MANAGED_SCOPE_SIG(n) Managed_Scope n(Application_Links *app, Buffer_ID buffer_id) -#define BUFFER_GET_TOKEN_ARRAY_SIG(n) Cpp_Token_Array n(Application_Links *app, Buffer_ID buffer_id) #define BUFFER_SEND_END_SIGNAL_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id) #define CREATE_BUFFER_SIG(n) Buffer_ID n(Application_Links *app, String_Const_u8 file_name, Buffer_Create_Flag flags) #define BUFFER_SAVE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_name, Buffer_Save_Flag flags) @@ -105,16 +102,15 @@ struct Application_Links; #define GET_MANAGED_SCOPE_WITH_MULTIPLE_DEPENDENCIES_SIG(n) Managed_Scope n(Application_Links *app, Managed_Scope *scopes, i32 count) #define MANAGED_SCOPE_CLEAR_CONTENTS_SIG(n) b32 n(Application_Links *app, Managed_Scope scope) #define MANAGED_SCOPE_CLEAR_SELF_ALL_DEPENDENT_SCOPES_SIG(n) b32 n(Application_Links *app, Managed_Scope scope) -#define MANAGED_VARIABLE_CREATE_SIG(n) Managed_Variable_ID n(Application_Links *app, char *null_terminated_name, u64 default_value) -#define MANAGED_VARIABLE_GET_ID_SIG(n) Managed_Variable_ID n(Application_Links *app, char *null_terminated_name) -#define MANAGED_VARIABLE_CREATE_OR_GET_ID_SIG(n) Managed_Variable_ID n(Application_Links *app, char *null_terminated_name, u64 default_value) -#define MANAGED_VARIABLE_SET_SIG(n) b32 n(Application_Links *app, Managed_Scope scope, Managed_Variable_ID id, u64 value) -#define MANAGED_VARIABLE_GET_SIG(n) b32 n(Application_Links *app, Managed_Scope scope, Managed_Variable_ID id, u64 *value_out) +#define MANAGED_SCOPE_ALLOCATOR_SIG(n) Base_Allocator* n(Application_Links *app, Managed_Scope scope) +#define MANAGED_ID_DECLARE_SIG(n) Managed_ID n(Application_Links *app, String_Const_u8 name) +#define MANAGED_SCOPE_GET_ATTACHMENT_SIG(n) void* n(Application_Links *app, Managed_Scope scope, Managed_ID id, umem size) +#define MANAGED_SCOPE_ATTACHMENT_ERASE_SIG(n) void* n(Application_Links *app, Managed_Scope scope, Managed_ID id) #define ALLOC_MANAGED_MEMORY_IN_SCOPE_SIG(n) Managed_Object n(Application_Links *app, Managed_Scope scope, i32 item_size, i32 count) #define ALLOC_BUFFER_MARKERS_ON_BUFFER_SIG(n) Managed_Object n(Application_Links *app, Buffer_ID buffer_id, i32 count, Managed_Scope *optional_extra_scope) -#define ALLOC_MANAGED_ARENA_IN_SCOPE_SIG(n) Managed_Object n(Application_Links *app, Managed_Scope scope, i32 page_size) #define MANAGED_OBJECT_GET_ITEM_SIZE_SIG(n) u32 n(Application_Links *app, Managed_Object object) #define MANAGED_OBJECT_GET_ITEM_COUNT_SIG(n) u32 n(Application_Links *app, Managed_Object object) +#define MANAGED_OBJECT_GET_POINTER_SIG(n) void* n(Application_Links *app, Managed_Object object) #define MANAGED_OBJECT_GET_TYPE_SIG(n) Managed_Object_Type n(Application_Links *app, Managed_Object object) #define MANAGED_OBJECT_GET_CONTAINING_SCOPE_SIG(n) Managed_Scope n(Application_Links *app, Managed_Object object) #define MANAGED_OBJECT_FREE_SIG(n) b32 n(Application_Links *app, Managed_Object object) @@ -198,7 +194,6 @@ typedef CHILD_PROCESS_GET_STATE_SIG(Child_Process_Get_State_Function); typedef CLIPBOARD_POST_SIG(Clipboard_Post_Function); typedef CLIPBOARD_COUNT_SIG(Clipboard_Count_Function); typedef PUSH_CLIPBOARD_INDEX_SIG(Push_Clipboard_Index_Function); -typedef CREATE_PARSE_CONTEXT_SIG(Create_Parse_Context_Function); typedef GET_BUFFER_COUNT_SIG(Get_Buffer_Count_Function); typedef GET_BUFFER_NEXT_SIG(Get_Buffer_Next_Function); typedef GET_BUFFER_BY_NAME_SIG(Get_Buffer_By_Name_Function); @@ -230,11 +225,9 @@ typedef PUSH_BUFFER_UNIQUE_NAME_SIG(Push_Buffer_Unique_Name_Function); typedef PUSH_BUFFER_FILE_NAME_SIG(Push_Buffer_File_Name_Function); typedef BUFFER_GET_DIRTY_STATE_SIG(Buffer_Get_Dirty_State_Function); typedef BUFFER_SET_DIRTY_STATE_SIG(Buffer_Set_Dirty_State_Function); -typedef BUFFER_TOKENS_ARE_READY_SIG(Buffer_Tokens_Are_Ready_Function); typedef BUFFER_GET_SETTING_SIG(Buffer_Get_Setting_Function); typedef BUFFER_SET_SETTING_SIG(Buffer_Set_Setting_Function); typedef BUFFER_GET_MANAGED_SCOPE_SIG(Buffer_Get_Managed_Scope_Function); -typedef BUFFER_GET_TOKEN_ARRAY_SIG(Buffer_Get_Token_Array_Function); typedef BUFFER_SEND_END_SIGNAL_SIG(Buffer_Send_End_Signal_Function); typedef CREATE_BUFFER_SIG(Create_Buffer_Function); typedef BUFFER_SAVE_SIG(Buffer_Save_Function); @@ -291,16 +284,15 @@ typedef GET_GLOBAL_MANAGED_SCOPE_SIG(Get_Global_Managed_Scope_Function); typedef GET_MANAGED_SCOPE_WITH_MULTIPLE_DEPENDENCIES_SIG(Get_Managed_Scope_With_Multiple_Dependencies_Function); typedef MANAGED_SCOPE_CLEAR_CONTENTS_SIG(Managed_Scope_Clear_Contents_Function); typedef MANAGED_SCOPE_CLEAR_SELF_ALL_DEPENDENT_SCOPES_SIG(Managed_Scope_Clear_Self_All_Dependent_Scopes_Function); -typedef MANAGED_VARIABLE_CREATE_SIG(Managed_Variable_Create_Function); -typedef MANAGED_VARIABLE_GET_ID_SIG(Managed_Variable_Get_ID_Function); -typedef MANAGED_VARIABLE_CREATE_OR_GET_ID_SIG(Managed_Variable_Create_Or_Get_ID_Function); -typedef MANAGED_VARIABLE_SET_SIG(Managed_Variable_Set_Function); -typedef MANAGED_VARIABLE_GET_SIG(Managed_Variable_Get_Function); +typedef MANAGED_SCOPE_ALLOCATOR_SIG(Managed_Scope_Allocator_Function); +typedef MANAGED_ID_DECLARE_SIG(Managed_Id_Declare_Function); +typedef MANAGED_SCOPE_GET_ATTACHMENT_SIG(Managed_Scope_Get_Attachment_Function); +typedef MANAGED_SCOPE_ATTACHMENT_ERASE_SIG(Managed_Scope_Attachment_Erase_Function); typedef ALLOC_MANAGED_MEMORY_IN_SCOPE_SIG(Alloc_Managed_Memory_In_Scope_Function); typedef ALLOC_BUFFER_MARKERS_ON_BUFFER_SIG(Alloc_Buffer_Markers_On_Buffer_Function); -typedef ALLOC_MANAGED_ARENA_IN_SCOPE_SIG(Alloc_Managed_Arena_In_Scope_Function); typedef MANAGED_OBJECT_GET_ITEM_SIZE_SIG(Managed_Object_Get_Item_Size_Function); typedef MANAGED_OBJECT_GET_ITEM_COUNT_SIG(Managed_Object_Get_Item_Count_Function); +typedef MANAGED_OBJECT_GET_POINTER_SIG(Managed_Object_Get_Pointer_Function); typedef MANAGED_OBJECT_GET_TYPE_SIG(Managed_Object_Get_Type_Function); typedef MANAGED_OBJECT_GET_CONTAINING_SCOPE_SIG(Managed_Object_Get_Containing_Scope_Function); typedef MANAGED_OBJECT_FREE_SIG(Managed_Object_Free_Function); @@ -386,7 +378,6 @@ Child_Process_Get_State_Function *child_process_get_state; Clipboard_Post_Function *clipboard_post; Clipboard_Count_Function *clipboard_count; Push_Clipboard_Index_Function *push_clipboard_index; -Create_Parse_Context_Function *create_parse_context; Get_Buffer_Count_Function *get_buffer_count; Get_Buffer_Next_Function *get_buffer_next; Get_Buffer_By_Name_Function *get_buffer_by_name; @@ -418,11 +409,9 @@ Push_Buffer_Unique_Name_Function *push_buffer_unique_name; Push_Buffer_File_Name_Function *push_buffer_file_name; Buffer_Get_Dirty_State_Function *buffer_get_dirty_state; Buffer_Set_Dirty_State_Function *buffer_set_dirty_state; -Buffer_Tokens_Are_Ready_Function *buffer_tokens_are_ready; Buffer_Get_Setting_Function *buffer_get_setting; Buffer_Set_Setting_Function *buffer_set_setting; Buffer_Get_Managed_Scope_Function *buffer_get_managed_scope; -Buffer_Get_Token_Array_Function *buffer_get_token_array; Buffer_Send_End_Signal_Function *buffer_send_end_signal; Create_Buffer_Function *create_buffer; Buffer_Save_Function *buffer_save; @@ -479,16 +468,15 @@ Get_Global_Managed_Scope_Function *get_global_managed_scope; Get_Managed_Scope_With_Multiple_Dependencies_Function *get_managed_scope_with_multiple_dependencies; Managed_Scope_Clear_Contents_Function *managed_scope_clear_contents; Managed_Scope_Clear_Self_All_Dependent_Scopes_Function *managed_scope_clear_self_all_dependent_scopes; -Managed_Variable_Create_Function *managed_variable_create; -Managed_Variable_Get_ID_Function *managed_variable_get_id; -Managed_Variable_Create_Or_Get_ID_Function *managed_variable_create_or_get_id; -Managed_Variable_Set_Function *managed_variable_set; -Managed_Variable_Get_Function *managed_variable_get; +Managed_Scope_Allocator_Function *managed_scope_allocator; +Managed_Id_Declare_Function *managed_id_declare; +Managed_Scope_Get_Attachment_Function *managed_scope_get_attachment; +Managed_Scope_Attachment_Erase_Function *managed_scope_attachment_erase; Alloc_Managed_Memory_In_Scope_Function *alloc_managed_memory_in_scope; Alloc_Buffer_Markers_On_Buffer_Function *alloc_buffer_markers_on_buffer; -Alloc_Managed_Arena_In_Scope_Function *alloc_managed_arena_in_scope; Managed_Object_Get_Item_Size_Function *managed_object_get_item_size; Managed_Object_Get_Item_Count_Function *managed_object_get_item_count; +Managed_Object_Get_Pointer_Function *managed_object_get_pointer; Managed_Object_Get_Type_Function *managed_object_get_type; Managed_Object_Get_Containing_Scope_Function *managed_object_get_containing_scope; Managed_Object_Free_Function *managed_object_free; @@ -573,7 +561,6 @@ Child_Process_Get_State_Function *child_process_get_state_; Clipboard_Post_Function *clipboard_post_; Clipboard_Count_Function *clipboard_count_; Push_Clipboard_Index_Function *push_clipboard_index_; -Create_Parse_Context_Function *create_parse_context_; Get_Buffer_Count_Function *get_buffer_count_; Get_Buffer_Next_Function *get_buffer_next_; Get_Buffer_By_Name_Function *get_buffer_by_name_; @@ -605,11 +592,9 @@ Push_Buffer_Unique_Name_Function *push_buffer_unique_name_; Push_Buffer_File_Name_Function *push_buffer_file_name_; Buffer_Get_Dirty_State_Function *buffer_get_dirty_state_; Buffer_Set_Dirty_State_Function *buffer_set_dirty_state_; -Buffer_Tokens_Are_Ready_Function *buffer_tokens_are_ready_; Buffer_Get_Setting_Function *buffer_get_setting_; Buffer_Set_Setting_Function *buffer_set_setting_; Buffer_Get_Managed_Scope_Function *buffer_get_managed_scope_; -Buffer_Get_Token_Array_Function *buffer_get_token_array_; Buffer_Send_End_Signal_Function *buffer_send_end_signal_; Create_Buffer_Function *create_buffer_; Buffer_Save_Function *buffer_save_; @@ -666,16 +651,15 @@ Get_Global_Managed_Scope_Function *get_global_managed_scope_; Get_Managed_Scope_With_Multiple_Dependencies_Function *get_managed_scope_with_multiple_dependencies_; Managed_Scope_Clear_Contents_Function *managed_scope_clear_contents_; Managed_Scope_Clear_Self_All_Dependent_Scopes_Function *managed_scope_clear_self_all_dependent_scopes_; -Managed_Variable_Create_Function *managed_variable_create_; -Managed_Variable_Get_ID_Function *managed_variable_get_id_; -Managed_Variable_Create_Or_Get_ID_Function *managed_variable_create_or_get_id_; -Managed_Variable_Set_Function *managed_variable_set_; -Managed_Variable_Get_Function *managed_variable_get_; +Managed_Scope_Allocator_Function *managed_scope_allocator_; +Managed_Id_Declare_Function *managed_id_declare_; +Managed_Scope_Get_Attachment_Function *managed_scope_get_attachment_; +Managed_Scope_Attachment_Erase_Function *managed_scope_attachment_erase_; Alloc_Managed_Memory_In_Scope_Function *alloc_managed_memory_in_scope_; Alloc_Buffer_Markers_On_Buffer_Function *alloc_buffer_markers_on_buffer_; -Alloc_Managed_Arena_In_Scope_Function *alloc_managed_arena_in_scope_; Managed_Object_Get_Item_Size_Function *managed_object_get_item_size_; Managed_Object_Get_Item_Count_Function *managed_object_get_item_count_; +Managed_Object_Get_Pointer_Function *managed_object_get_pointer_; Managed_Object_Get_Type_Function *managed_object_get_type_; Managed_Object_Get_Containing_Scope_Function *managed_object_get_containing_scope_; Managed_Object_Free_Function *managed_object_free_; @@ -768,7 +752,6 @@ app_links->child_process_get_state_ = Child_Process_Get_State;\ app_links->clipboard_post_ = Clipboard_Post;\ app_links->clipboard_count_ = Clipboard_Count;\ app_links->push_clipboard_index_ = Push_Clipboard_Index;\ -app_links->create_parse_context_ = Create_Parse_Context;\ app_links->get_buffer_count_ = Get_Buffer_Count;\ app_links->get_buffer_next_ = Get_Buffer_Next;\ app_links->get_buffer_by_name_ = Get_Buffer_By_Name;\ @@ -800,11 +783,9 @@ app_links->push_buffer_unique_name_ = Push_Buffer_Unique_Name;\ app_links->push_buffer_file_name_ = Push_Buffer_File_Name;\ app_links->buffer_get_dirty_state_ = Buffer_Get_Dirty_State;\ app_links->buffer_set_dirty_state_ = Buffer_Set_Dirty_State;\ -app_links->buffer_tokens_are_ready_ = Buffer_Tokens_Are_Ready;\ app_links->buffer_get_setting_ = Buffer_Get_Setting;\ app_links->buffer_set_setting_ = Buffer_Set_Setting;\ app_links->buffer_get_managed_scope_ = Buffer_Get_Managed_Scope;\ -app_links->buffer_get_token_array_ = Buffer_Get_Token_Array;\ app_links->buffer_send_end_signal_ = Buffer_Send_End_Signal;\ app_links->create_buffer_ = Create_Buffer;\ app_links->buffer_save_ = Buffer_Save;\ @@ -861,16 +842,15 @@ app_links->get_global_managed_scope_ = Get_Global_Managed_Scope;\ app_links->get_managed_scope_with_multiple_dependencies_ = Get_Managed_Scope_With_Multiple_Dependencies;\ app_links->managed_scope_clear_contents_ = Managed_Scope_Clear_Contents;\ app_links->managed_scope_clear_self_all_dependent_scopes_ = Managed_Scope_Clear_Self_All_Dependent_Scopes;\ -app_links->managed_variable_create_ = Managed_Variable_Create;\ -app_links->managed_variable_get_id_ = Managed_Variable_Get_ID;\ -app_links->managed_variable_create_or_get_id_ = Managed_Variable_Create_Or_Get_ID;\ -app_links->managed_variable_set_ = Managed_Variable_Set;\ -app_links->managed_variable_get_ = Managed_Variable_Get;\ +app_links->managed_scope_allocator_ = Managed_Scope_Allocator;\ +app_links->managed_id_declare_ = Managed_Id_Declare;\ +app_links->managed_scope_get_attachment_ = Managed_Scope_Get_Attachment;\ +app_links->managed_scope_attachment_erase_ = Managed_Scope_Attachment_Erase;\ app_links->alloc_managed_memory_in_scope_ = Alloc_Managed_Memory_In_Scope;\ app_links->alloc_buffer_markers_on_buffer_ = Alloc_Buffer_Markers_On_Buffer;\ -app_links->alloc_managed_arena_in_scope_ = Alloc_Managed_Arena_In_Scope;\ app_links->managed_object_get_item_size_ = Managed_Object_Get_Item_Size;\ app_links->managed_object_get_item_count_ = Managed_Object_Get_Item_Count;\ +app_links->managed_object_get_pointer_ = Managed_Object_Get_Pointer;\ app_links->managed_object_get_type_ = Managed_Object_Get_Type;\ app_links->managed_object_get_containing_scope_ = Managed_Object_Get_Containing_Scope;\ app_links->managed_object_free_ = Managed_Object_Free;\ @@ -955,7 +935,6 @@ static Process_State child_process_get_state(Application_Links *app, Child_Proce static b32 clipboard_post(Application_Links *app, i32 clipboard_id, String_Const_u8 string){return(app->clipboard_post(app, clipboard_id, string));} static i32 clipboard_count(Application_Links *app, i32 clipboard_id){return(app->clipboard_count(app, clipboard_id));} static String_Const_u8 push_clipboard_index(Application_Links *app, Arena *arena, i32 clipboard_id, i32 item_index){return(app->push_clipboard_index(app, arena, clipboard_id, item_index));} -static Parse_Context_ID create_parse_context(Application_Links *app, Parser_String_And_Type *kw, u32 kw_count, Parser_String_And_Type *pp, u32 pp_count){return(app->create_parse_context(app, kw, kw_count, pp, pp_count));} static i32 get_buffer_count(Application_Links *app){return(app->get_buffer_count(app));} static Buffer_ID get_buffer_next(Application_Links *app, Buffer_ID buffer_id, Access_Flag access){return(app->get_buffer_next(app, buffer_id, access));} static Buffer_ID get_buffer_by_name(Application_Links *app, String_Const_u8 name, Access_Flag access){return(app->get_buffer_by_name(app, name, access));} @@ -987,11 +966,9 @@ static String_Const_u8 push_buffer_unique_name(Application_Links *app, Arena *ou static String_Const_u8 push_buffer_file_name(Application_Links *app, Arena *arena, Buffer_ID buffer_id){return(app->push_buffer_file_name(app, arena, buffer_id));} static Dirty_State buffer_get_dirty_state(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_get_dirty_state(app, buffer_id));} static b32 buffer_set_dirty_state(Application_Links *app, Buffer_ID buffer_id, Dirty_State dirty_state){return(app->buffer_set_dirty_state(app, buffer_id, dirty_state));} -static b32 buffer_tokens_are_ready(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_tokens_are_ready(app, buffer_id));} static b32 buffer_get_setting(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_ID setting, i32 *value_out){return(app->buffer_get_setting(app, buffer_id, setting, value_out));} static b32 buffer_set_setting(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_ID setting, i32 value){return(app->buffer_set_setting(app, buffer_id, setting, value));} static Managed_Scope buffer_get_managed_scope(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_get_managed_scope(app, buffer_id));} -static Cpp_Token_Array buffer_get_token_array(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_get_token_array(app, buffer_id));} static b32 buffer_send_end_signal(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_send_end_signal(app, buffer_id));} static Buffer_ID create_buffer(Application_Links *app, String_Const_u8 file_name, Buffer_Create_Flag flags){return(app->create_buffer(app, file_name, flags));} static b32 buffer_save(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_name, Buffer_Save_Flag flags){return(app->buffer_save(app, buffer_id, file_name, flags));} @@ -1048,16 +1025,15 @@ static Managed_Scope get_global_managed_scope(Application_Links *app){return(app static Managed_Scope get_managed_scope_with_multiple_dependencies(Application_Links *app, Managed_Scope *scopes, i32 count){return(app->get_managed_scope_with_multiple_dependencies(app, scopes, count));} static b32 managed_scope_clear_contents(Application_Links *app, Managed_Scope scope){return(app->managed_scope_clear_contents(app, scope));} static b32 managed_scope_clear_self_all_dependent_scopes(Application_Links *app, Managed_Scope scope){return(app->managed_scope_clear_self_all_dependent_scopes(app, scope));} -static Managed_Variable_ID managed_variable_create(Application_Links *app, char *null_terminated_name, u64 default_value){return(app->managed_variable_create(app, null_terminated_name, default_value));} -static Managed_Variable_ID managed_variable_get_id(Application_Links *app, char *null_terminated_name){return(app->managed_variable_get_id(app, null_terminated_name));} -static Managed_Variable_ID managed_variable_create_or_get_id(Application_Links *app, char *null_terminated_name, u64 default_value){return(app->managed_variable_create_or_get_id(app, null_terminated_name, default_value));} -static b32 managed_variable_set(Application_Links *app, Managed_Scope scope, Managed_Variable_ID id, u64 value){return(app->managed_variable_set(app, scope, id, value));} -static b32 managed_variable_get(Application_Links *app, Managed_Scope scope, Managed_Variable_ID id, u64 *value_out){return(app->managed_variable_get(app, scope, id, value_out));} +static Base_Allocator* managed_scope_allocator(Application_Links *app, Managed_Scope scope){return(app->managed_scope_allocator(app, scope));} +static Managed_ID managed_id_declare(Application_Links *app, String_Const_u8 name){return(app->managed_id_declare(app, name));} +static void* managed_scope_get_attachment(Application_Links *app, Managed_Scope scope, Managed_ID id, umem size){return(app->managed_scope_get_attachment(app, scope, id, size));} +static void* managed_scope_attachment_erase(Application_Links *app, Managed_Scope scope, Managed_ID id){return(app->managed_scope_attachment_erase(app, scope, id));} static Managed_Object alloc_managed_memory_in_scope(Application_Links *app, Managed_Scope scope, i32 item_size, i32 count){return(app->alloc_managed_memory_in_scope(app, scope, item_size, count));} static Managed_Object alloc_buffer_markers_on_buffer(Application_Links *app, Buffer_ID buffer_id, i32 count, Managed_Scope *optional_extra_scope){return(app->alloc_buffer_markers_on_buffer(app, buffer_id, count, optional_extra_scope));} -static Managed_Object alloc_managed_arena_in_scope(Application_Links *app, Managed_Scope scope, i32 page_size){return(app->alloc_managed_arena_in_scope(app, scope, page_size));} static u32 managed_object_get_item_size(Application_Links *app, Managed_Object object){return(app->managed_object_get_item_size(app, object));} static u32 managed_object_get_item_count(Application_Links *app, Managed_Object object){return(app->managed_object_get_item_count(app, object));} +static void* managed_object_get_pointer(Application_Links *app, Managed_Object object){return(app->managed_object_get_pointer(app, object));} static Managed_Object_Type managed_object_get_type(Application_Links *app, Managed_Object object){return(app->managed_object_get_type(app, object));} static Managed_Scope managed_object_get_containing_scope(Application_Links *app, Managed_Object object){return(app->managed_object_get_containing_scope(app, object));} static b32 managed_object_free(Application_Links *app, Managed_Object object){return(app->managed_object_free(app, object));} @@ -1142,7 +1118,6 @@ static Process_State child_process_get_state(Application_Links *app, Child_Proce static b32 clipboard_post(Application_Links *app, i32 clipboard_id, String_Const_u8 string){return(app->clipboard_post_(app, clipboard_id, string));} static i32 clipboard_count(Application_Links *app, i32 clipboard_id){return(app->clipboard_count_(app, clipboard_id));} static String_Const_u8 push_clipboard_index(Application_Links *app, Arena *arena, i32 clipboard_id, i32 item_index){return(app->push_clipboard_index_(app, arena, clipboard_id, item_index));} -static Parse_Context_ID create_parse_context(Application_Links *app, Parser_String_And_Type *kw, u32 kw_count, Parser_String_And_Type *pp, u32 pp_count){return(app->create_parse_context_(app, kw, kw_count, pp, pp_count));} static i32 get_buffer_count(Application_Links *app){return(app->get_buffer_count_(app));} static Buffer_ID get_buffer_next(Application_Links *app, Buffer_ID buffer_id, Access_Flag access){return(app->get_buffer_next_(app, buffer_id, access));} static Buffer_ID get_buffer_by_name(Application_Links *app, String_Const_u8 name, Access_Flag access){return(app->get_buffer_by_name_(app, name, access));} @@ -1174,11 +1149,9 @@ static String_Const_u8 push_buffer_unique_name(Application_Links *app, Arena *ou static String_Const_u8 push_buffer_file_name(Application_Links *app, Arena *arena, Buffer_ID buffer_id){return(app->push_buffer_file_name_(app, arena, buffer_id));} static Dirty_State buffer_get_dirty_state(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_get_dirty_state_(app, buffer_id));} static b32 buffer_set_dirty_state(Application_Links *app, Buffer_ID buffer_id, Dirty_State dirty_state){return(app->buffer_set_dirty_state_(app, buffer_id, dirty_state));} -static b32 buffer_tokens_are_ready(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_tokens_are_ready_(app, buffer_id));} static b32 buffer_get_setting(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_ID setting, i32 *value_out){return(app->buffer_get_setting_(app, buffer_id, setting, value_out));} static b32 buffer_set_setting(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_ID setting, i32 value){return(app->buffer_set_setting_(app, buffer_id, setting, value));} static Managed_Scope buffer_get_managed_scope(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_get_managed_scope_(app, buffer_id));} -static Cpp_Token_Array buffer_get_token_array(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_get_token_array_(app, buffer_id));} static b32 buffer_send_end_signal(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_send_end_signal_(app, buffer_id));} static Buffer_ID create_buffer(Application_Links *app, String_Const_u8 file_name, Buffer_Create_Flag flags){return(app->create_buffer_(app, file_name, flags));} static b32 buffer_save(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_name, Buffer_Save_Flag flags){return(app->buffer_save_(app, buffer_id, file_name, flags));} @@ -1235,16 +1208,15 @@ static Managed_Scope get_global_managed_scope(Application_Links *app){return(app static Managed_Scope get_managed_scope_with_multiple_dependencies(Application_Links *app, Managed_Scope *scopes, i32 count){return(app->get_managed_scope_with_multiple_dependencies_(app, scopes, count));} static b32 managed_scope_clear_contents(Application_Links *app, Managed_Scope scope){return(app->managed_scope_clear_contents_(app, scope));} static b32 managed_scope_clear_self_all_dependent_scopes(Application_Links *app, Managed_Scope scope){return(app->managed_scope_clear_self_all_dependent_scopes_(app, scope));} -static Managed_Variable_ID managed_variable_create(Application_Links *app, char *null_terminated_name, u64 default_value){return(app->managed_variable_create_(app, null_terminated_name, default_value));} -static Managed_Variable_ID managed_variable_get_id(Application_Links *app, char *null_terminated_name){return(app->managed_variable_get_id_(app, null_terminated_name));} -static Managed_Variable_ID managed_variable_create_or_get_id(Application_Links *app, char *null_terminated_name, u64 default_value){return(app->managed_variable_create_or_get_id_(app, null_terminated_name, default_value));} -static b32 managed_variable_set(Application_Links *app, Managed_Scope scope, Managed_Variable_ID id, u64 value){return(app->managed_variable_set_(app, scope, id, value));} -static b32 managed_variable_get(Application_Links *app, Managed_Scope scope, Managed_Variable_ID id, u64 *value_out){return(app->managed_variable_get_(app, scope, id, value_out));} +static Base_Allocator* managed_scope_allocator(Application_Links *app, Managed_Scope scope){return(app->managed_scope_allocator_(app, scope));} +static Managed_ID managed_id_declare(Application_Links *app, String_Const_u8 name){return(app->managed_id_declare_(app, name));} +static void* managed_scope_get_attachment(Application_Links *app, Managed_Scope scope, Managed_ID id, umem size){return(app->managed_scope_get_attachment_(app, scope, id, size));} +static void* managed_scope_attachment_erase(Application_Links *app, Managed_Scope scope, Managed_ID id){return(app->managed_scope_attachment_erase_(app, scope, id));} static Managed_Object alloc_managed_memory_in_scope(Application_Links *app, Managed_Scope scope, i32 item_size, i32 count){return(app->alloc_managed_memory_in_scope_(app, scope, item_size, count));} static Managed_Object alloc_buffer_markers_on_buffer(Application_Links *app, Buffer_ID buffer_id, i32 count, Managed_Scope *optional_extra_scope){return(app->alloc_buffer_markers_on_buffer_(app, buffer_id, count, optional_extra_scope));} -static Managed_Object alloc_managed_arena_in_scope(Application_Links *app, Managed_Scope scope, i32 page_size){return(app->alloc_managed_arena_in_scope_(app, scope, page_size));} static u32 managed_object_get_item_size(Application_Links *app, Managed_Object object){return(app->managed_object_get_item_size_(app, object));} static u32 managed_object_get_item_count(Application_Links *app, Managed_Object object){return(app->managed_object_get_item_count_(app, object));} +static void* managed_object_get_pointer(Application_Links *app, Managed_Object object){return(app->managed_object_get_pointer_(app, object));} static Managed_Object_Type managed_object_get_type(Application_Links *app, Managed_Object object){return(app->managed_object_get_type_(app, object));} static Managed_Scope managed_object_get_containing_scope(Application_Links *app, Managed_Object object){return(app->managed_object_get_containing_scope_(app, object));} static b32 managed_object_free(Application_Links *app, Managed_Object object){return(app->managed_object_free_(app, object));} diff --git a/4coder_generated/command_metadata.h b/4coder_generated/command_metadata.h index b0eb938f..e7e1aebb 100644 --- a/4coder_generated/command_metadata.h +++ b/4coder_generated/command_metadata.h @@ -254,7 +254,7 @@ int32_t source_name_len; int32_t line_number; }; static Command_Metadata fcoder_metacmd_table[233] = { -{ PROC_LINKS(write_explicit_enum_flags, 0), "write_explicit_enum_flags", 25, "If the cursor is found to be on the '{' of an enum definition, the values of the enum will be filled in to give each a unique power of 2 value, starting from 1. Existing values are overwritten.", 194, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 504 }, +{ PROC_LINKS(write_explicit_enum_flags, 0), "write_explicit_enum_flags", 25, "If the cursor is found to be on the '{' of an enum definition, the values of the enum will be filled in to give each a unique power of 2 value, starting from 1. Existing values are overwritten.", 194, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 502 }, { PROC_LINKS(seek_beginning_of_textual_line, 0), "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "w:\\4ed\\code\\4coder_seek.cpp", 27, 29 }, { PROC_LINKS(seek_end_of_textual_line, 0), "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "w:\\4ed\\code\\4coder_seek.cpp", 27, 35 }, { PROC_LINKS(seek_beginning_of_line, 0), "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "w:\\4ed\\code\\4coder_seek.cpp", 27, 41 }, @@ -265,16 +265,16 @@ static Command_Metadata fcoder_metacmd_table[233] = { { PROC_LINKS(change_active_panel_backwards, 0), "change_active_panel_backwards", 29, "Change the currently active panel, moving to the panel with the next lowest view_id.", 84, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 211 }, { PROC_LINKS(open_panel_vsplit, 0), "open_panel_vsplit", 17, "Create a new panel by vertically splitting the active panel.", 60, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 221 }, { PROC_LINKS(open_panel_hsplit, 0), "open_panel_hsplit", 17, "Create a new panel by horizontally splitting the active panel.", 62, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 231 }, -{ PROC_LINKS(suppress_mouse, 0), "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 292 }, -{ PROC_LINKS(allow_mouse, 0), "allow_mouse", 11, "Shows the mouse and causes all mouse input to be processed normally.", 68, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 298 }, -{ PROC_LINKS(toggle_mouse, 0), "toggle_mouse", 12, "Toggles the mouse suppression mode, see suppress_mouse and allow_mouse.", 71, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 304 }, -{ PROC_LINKS(set_mode_to_original, 0), "set_mode_to_original", 20, "Sets the edit mode to 4coder original.", 38, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 310 }, -{ PROC_LINKS(set_mode_to_notepad_like, 0), "set_mode_to_notepad_like", 24, "Sets the edit mode to Notepad like.", 35, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 316 }, -{ PROC_LINKS(toggle_highlight_line_at_cursor, 0), "toggle_highlight_line_at_cursor", 31, "Toggles the line highlight at the cursor.", 41, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 322 }, -{ PROC_LINKS(toggle_highlight_enclosing_scopes, 0), "toggle_highlight_enclosing_scopes", 33, "In code files scopes surrounding the cursor are highlighted with distinguishing colors.", 87, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 328 }, -{ PROC_LINKS(toggle_paren_matching_helper, 0), "toggle_paren_matching_helper", 28, "In code files matching parentheses pairs are colored with distinguishing colors.", 80, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 334 }, -{ PROC_LINKS(toggle_fullscreen, 0), "toggle_fullscreen", 17, "Toggle fullscreen mode on or off. The change(s) do not take effect until the next frame.", 89, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 340 }, -{ PROC_LINKS(remap_interactive, 0), "remap_interactive", 17, "Switch to a named key binding map.", 34, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 348 }, +{ PROC_LINKS(suppress_mouse, 0), "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 294 }, +{ PROC_LINKS(allow_mouse, 0), "allow_mouse", 11, "Shows the mouse and causes all mouse input to be processed normally.", 68, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 300 }, +{ PROC_LINKS(toggle_mouse, 0), "toggle_mouse", 12, "Toggles the mouse suppression mode, see suppress_mouse and allow_mouse.", 71, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 306 }, +{ PROC_LINKS(set_mode_to_original, 0), "set_mode_to_original", 20, "Sets the edit mode to 4coder original.", 38, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 312 }, +{ PROC_LINKS(set_mode_to_notepad_like, 0), "set_mode_to_notepad_like", 24, "Sets the edit mode to Notepad like.", 35, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 318 }, +{ PROC_LINKS(toggle_highlight_line_at_cursor, 0), "toggle_highlight_line_at_cursor", 31, "Toggles the line highlight at the cursor.", 41, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 324 }, +{ PROC_LINKS(toggle_highlight_enclosing_scopes, 0), "toggle_highlight_enclosing_scopes", 33, "In code files scopes surrounding the cursor are highlighted with distinguishing colors.", 87, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 330 }, +{ PROC_LINKS(toggle_paren_matching_helper, 0), "toggle_paren_matching_helper", 28, "In code files matching parentheses pairs are colored with distinguishing colors.", 80, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 336 }, +{ PROC_LINKS(toggle_fullscreen, 0), "toggle_fullscreen", 17, "Toggle fullscreen mode on or off. The change(s) do not take effect until the next frame.", 89, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 342 }, +{ PROC_LINKS(remap_interactive, 0), "remap_interactive", 17, "Switch to a named key binding map.", 34, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 350 }, { PROC_LINKS(write_character, 0), "write_character", 15, "Inserts whatever character was used to trigger this command.", 60, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 57 }, { PROC_LINKS(write_underscore, 0), "write_underscore", 16, "Inserts an underscore.", 22, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 66 }, { PROC_LINKS(delete_char, 0), "delete_char", 11, "Deletes the character to the right of the cursor.", 49, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 73 }, @@ -330,50 +330,50 @@ static Command_Metadata fcoder_metacmd_table[233] = { { PROC_LINKS(hide_filebar, 0), "hide_filebar", 12, "Sets the current view to hide it's filebar.", 43, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 679 }, { PROC_LINKS(toggle_filebar, 0), "toggle_filebar", 14, "Toggles the visibility status of the current view's filebar.", 60, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 686 }, { PROC_LINKS(toggle_line_wrap, 0), "toggle_line_wrap", 16, "Toggles the current buffer's line wrapping status.", 50, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 695 }, -{ PROC_LINKS(toggle_fps_meter, 0), "toggle_fps_meter", 16, "Toggles the visibility of the FPS performance meter", 51, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 705 }, -{ PROC_LINKS(increase_line_wrap, 0), "increase_line_wrap", 18, "Increases the current buffer's width for line wrapping.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 711 }, -{ PROC_LINKS(decrease_line_wrap, 0), "decrease_line_wrap", 18, "Decrases the current buffer's width for line wrapping.", 54, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 721 }, -{ PROC_LINKS(increase_face_size, 0), "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 731 }, -{ PROC_LINKS(decrease_face_size, 0), "decrease_face_size", 18, "Decrease the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 742 }, -{ PROC_LINKS(mouse_wheel_change_face_size, 0), "mouse_wheel_change_face_size", 28, "Reads the state of the mouse wheel and uses it to either increase or decrease the face size.", 92, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 753 }, -{ PROC_LINKS(toggle_virtual_whitespace, 0), "toggle_virtual_whitespace", 25, "Toggles the current buffer's virtual whitespace status.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 770 }, -{ PROC_LINKS(toggle_show_whitespace, 0), "toggle_show_whitespace", 22, "Toggles the current buffer's whitespace visibility status.", 58, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 780 }, -{ PROC_LINKS(toggle_line_numbers, 0), "toggle_line_numbers", 19, "Toggles the left margin line numbers.", 37, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 789 }, -{ PROC_LINKS(eol_dosify, 0), "eol_dosify", 10, "Puts the buffer in DOS line ending mode.", 40, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 795 }, -{ PROC_LINKS(eol_nixify, 0), "eol_nixify", 10, "Puts the buffer in NIX line ending mode.", 40, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 803 }, -{ PROC_LINKS(exit_4coder, 0), "exit_4coder", 11, "Attempts to close 4coder.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 811 }, -{ PROC_LINKS(goto_line, 0), "goto_line", 9, "Queries the user for a number, and jumps the cursor to the corresponding line.", 78, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 819 }, -{ PROC_LINKS(search, 0), "search", 6, "Begins an incremental search down through the current buffer for a user specified string.", 89, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1030 }, -{ PROC_LINKS(reverse_search, 0), "reverse_search", 14, "Begins an incremental search up through the current buffer for a user specified string.", 87, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1036 }, -{ PROC_LINKS(search_identifier, 0), "search_identifier", 17, "Begins an incremental search down through the current buffer for the word or token under the cursor.", 100, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1042 }, -{ PROC_LINKS(reverse_search_identifier, 0), "reverse_search_identifier", 25, "Begins an incremental search up through the current buffer for the word or token under the cursor.", 98, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1053 }, -{ PROC_LINKS(replace_in_range, 0), "replace_in_range", 16, "Queries the user for a needle and string. Replaces all occurences of needle with string in the range between cursor and the mark in the active buffer.", 150, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1104 }, -{ PROC_LINKS(replace_in_buffer, 0), "replace_in_buffer", 17, "Queries the user for a needle and string. Replaces all occurences of needle with string in the active buffer.", 109, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1113 }, -{ PROC_LINKS(replace_in_all_buffers, 0), "replace_in_all_buffers", 22, "Queries the user for a needle and string. Replaces all occurences of needle with string in all editable buffers.", 112, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1122 }, -{ PROC_LINKS(query_replace, 0), "query_replace", 13, "Queries the user for two strings, and incrementally replaces every occurence of the first string with the second string.", 120, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1210 }, -{ PROC_LINKS(query_replace_identifier, 0), "query_replace_identifier", 24, "Queries the user for a string, and incrementally replace every occurence of the word or token found at the cursor with the specified string.", 140, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1230 }, -{ PROC_LINKS(query_replace_selection, 0), "query_replace_selection", 23, "Queries the user for a string, and incrementally replace every occurence of the string found in the selected range with the specified string.", 141, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1246 }, -{ PROC_LINKS(save_all_dirty_buffers, 0), "save_all_dirty_buffers", 22, "Saves all buffers marked dirty (showing the '*' indicator).", 59, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1281 }, -{ PROC_LINKS(delete_file_query, 0), "delete_file_query", 17, "Deletes the file of the current buffer if 4coder has the appropriate access rights. Will ask the user for confirmation first.", 125, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1306 }, -{ PROC_LINKS(save_to_query, 0), "save_to_query", 13, "Queries the user for a file name and saves the contents of the current buffer, altering the buffer's name too.", 110, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1344 }, -{ PROC_LINKS(rename_file_query, 0), "rename_file_query", 17, "Queries the user for a new name and renames the file of the current buffer, altering the buffer's name too.", 107, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1379 }, -{ PROC_LINKS(make_directory_query, 0), "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1419 }, -{ PROC_LINKS(move_line_up, 0), "move_line_up", 12, "Swaps the line under the cursor with the line above it, and moves the cursor up with it.", 88, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1452 }, -{ PROC_LINKS(move_line_down, 0), "move_line_down", 14, "Swaps the line under the cursor with the line below it, and moves the cursor down with it.", 90, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1458 }, -{ PROC_LINKS(duplicate_line, 0), "duplicate_line", 14, "Create a copy of the line on which the cursor sits.", 51, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1464 }, -{ PROC_LINKS(delete_line, 0), "delete_line", 11, "Delete the line the on which the cursor sits.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1478 }, -{ PROC_LINKS(open_file_in_quotes, 0), "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1543 }, -{ PROC_LINKS(open_matching_file_cpp, 0), "open_matching_file_cpp", 22, "If the current file is a *.cpp or *.h, attempts to open the corresponding *.h or *.cpp file in the other view.", 110, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1575 }, -{ PROC_LINKS(view_buffer_other_panel, 0), "view_buffer_other_panel", 23, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1588 }, -{ PROC_LINKS(swap_buffers_between_panels, 0), "swap_buffers_between_panels", 27, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1600 }, -{ PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1636 }, -{ PROC_LINKS(save, 0), "save", 4, "Saves the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1644 }, -{ PROC_LINKS(reopen, 0), "reopen", 6, "Reopen the current buffer from the hard drive.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1656 }, -{ PROC_LINKS(undo, 0), "undo", 4, "Advances backwards through the undo history of the current buffer.", 66, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1714 }, -{ PROC_LINKS(redo, 0), "redo", 4, "Advances forwards through the undo history of the current buffer.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1727 }, -{ PROC_LINKS(undo_all_buffers, 0), "undo_all_buffers", 16, "Advances backward through the undo history in the buffer containing the most recent regular edit.", 97, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1741 }, -{ PROC_LINKS(redo_all_buffers, 0), "redo_all_buffers", 16, "Advances forward through the undo history in the buffer containing the most recent regular edit.", 96, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1815 }, -{ PROC_LINKS(open_in_other, 0), "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1918 }, +{ PROC_LINKS(toggle_fps_meter, 0), "toggle_fps_meter", 16, "Toggles the visibility of the FPS performance meter", 51, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 708 }, +{ PROC_LINKS(increase_line_wrap, 0), "increase_line_wrap", 18, "Increases the current buffer's width for line wrapping.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 714 }, +{ PROC_LINKS(decrease_line_wrap, 0), "decrease_line_wrap", 18, "Decrases the current buffer's width for line wrapping.", 54, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 727 }, +{ PROC_LINKS(increase_face_size, 0), "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 740 }, +{ PROC_LINKS(decrease_face_size, 0), "decrease_face_size", 18, "Decrease the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 751 }, +{ PROC_LINKS(mouse_wheel_change_face_size, 0), "mouse_wheel_change_face_size", 28, "Reads the state of the mouse wheel and uses it to either increase or decrease the face size.", 92, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 762 }, +{ PROC_LINKS(toggle_virtual_whitespace, 0), "toggle_virtual_whitespace", 25, "Toggles the current buffer's virtual whitespace status.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 779 }, +{ PROC_LINKS(toggle_show_whitespace, 0), "toggle_show_whitespace", 22, "Toggles the current buffer's whitespace visibility status.", 58, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 789 }, +{ PROC_LINKS(toggle_line_numbers, 0), "toggle_line_numbers", 19, "Toggles the left margin line numbers.", 37, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 798 }, +{ PROC_LINKS(eol_dosify, 0), "eol_dosify", 10, "Puts the buffer in DOS line ending mode.", 40, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 804 }, +{ PROC_LINKS(eol_nixify, 0), "eol_nixify", 10, "Puts the buffer in NIX line ending mode.", 40, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 812 }, +{ PROC_LINKS(exit_4coder, 0), "exit_4coder", 11, "Attempts to close 4coder.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 820 }, +{ PROC_LINKS(goto_line, 0), "goto_line", 9, "Queries the user for a number, and jumps the cursor to the corresponding line.", 78, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 828 }, +{ PROC_LINKS(search, 0), "search", 6, "Begins an incremental search down through the current buffer for a user specified string.", 89, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1039 }, +{ PROC_LINKS(reverse_search, 0), "reverse_search", 14, "Begins an incremental search up through the current buffer for a user specified string.", 87, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1045 }, +{ PROC_LINKS(search_identifier, 0), "search_identifier", 17, "Begins an incremental search down through the current buffer for the word or token under the cursor.", 100, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1051 }, +{ PROC_LINKS(reverse_search_identifier, 0), "reverse_search_identifier", 25, "Begins an incremental search up through the current buffer for the word or token under the cursor.", 98, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1062 }, +{ PROC_LINKS(replace_in_range, 0), "replace_in_range", 16, "Queries the user for a needle and string. Replaces all occurences of needle with string in the range between cursor and the mark in the active buffer.", 150, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1113 }, +{ PROC_LINKS(replace_in_buffer, 0), "replace_in_buffer", 17, "Queries the user for a needle and string. Replaces all occurences of needle with string in the active buffer.", 109, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1122 }, +{ PROC_LINKS(replace_in_all_buffers, 0), "replace_in_all_buffers", 22, "Queries the user for a needle and string. Replaces all occurences of needle with string in all editable buffers.", 112, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1131 }, +{ PROC_LINKS(query_replace, 0), "query_replace", 13, "Queries the user for two strings, and incrementally replaces every occurence of the first string with the second string.", 120, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1219 }, +{ PROC_LINKS(query_replace_identifier, 0), "query_replace_identifier", 24, "Queries the user for a string, and incrementally replace every occurence of the word or token found at the cursor with the specified string.", 140, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1239 }, +{ PROC_LINKS(query_replace_selection, 0), "query_replace_selection", 23, "Queries the user for a string, and incrementally replace every occurence of the string found in the selected range with the specified string.", 141, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1255 }, +{ PROC_LINKS(save_all_dirty_buffers, 0), "save_all_dirty_buffers", 22, "Saves all buffers marked dirty (showing the '*' indicator).", 59, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1290 }, +{ PROC_LINKS(delete_file_query, 0), "delete_file_query", 17, "Deletes the file of the current buffer if 4coder has the appropriate access rights. Will ask the user for confirmation first.", 125, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1315 }, +{ PROC_LINKS(save_to_query, 0), "save_to_query", 13, "Queries the user for a file name and saves the contents of the current buffer, altering the buffer's name too.", 110, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1353 }, +{ PROC_LINKS(rename_file_query, 0), "rename_file_query", 17, "Queries the user for a new name and renames the file of the current buffer, altering the buffer's name too.", 107, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1388 }, +{ PROC_LINKS(make_directory_query, 0), "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1428 }, +{ PROC_LINKS(move_line_up, 0), "move_line_up", 12, "Swaps the line under the cursor with the line above it, and moves the cursor up with it.", 88, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1461 }, +{ PROC_LINKS(move_line_down, 0), "move_line_down", 14, "Swaps the line under the cursor with the line below it, and moves the cursor down with it.", 90, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1467 }, +{ PROC_LINKS(duplicate_line, 0), "duplicate_line", 14, "Create a copy of the line on which the cursor sits.", 51, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1473 }, +{ PROC_LINKS(delete_line, 0), "delete_line", 11, "Delete the line the on which the cursor sits.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1487 }, +{ PROC_LINKS(open_file_in_quotes, 0), "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1552 }, +{ PROC_LINKS(open_matching_file_cpp, 0), "open_matching_file_cpp", 22, "If the current file is a *.cpp or *.h, attempts to open the corresponding *.h or *.cpp file in the other view.", 110, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1584 }, +{ PROC_LINKS(view_buffer_other_panel, 0), "view_buffer_other_panel", 23, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1597 }, +{ PROC_LINKS(swap_buffers_between_panels, 0), "swap_buffers_between_panels", 27, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1609 }, +{ PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1645 }, +{ PROC_LINKS(save, 0), "save", 4, "Saves the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1653 }, +{ PROC_LINKS(reopen, 0), "reopen", 6, "Reopen the current buffer from the hard drive.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1665 }, +{ PROC_LINKS(undo, 0), "undo", 4, "Advances backwards through the undo history of the current buffer.", 66, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1723 }, +{ PROC_LINKS(redo, 0), "redo", 4, "Advances forwards through the undo history of the current buffer.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1736 }, +{ PROC_LINKS(undo_all_buffers, 0), "undo_all_buffers", 16, "Advances backward through the undo history in the buffer containing the most recent regular edit.", 97, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1750 }, +{ PROC_LINKS(redo_all_buffers, 0), "redo_all_buffers", 16, "Advances forward through the undo history in the buffer containing the most recent regular edit.", 96, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1824 }, +{ PROC_LINKS(open_in_other, 0), "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1927 }, { PROC_LINKS(lister__quit, 0), "lister__quit", 12, "A lister mode command that quits the list without executing any actions.", 72, "w:\\4ed\\code\\4coder_lists.cpp", 28, 8 }, { PROC_LINKS(lister__activate, 0), "lister__activate", 16, "A lister mode command that activates the list's action on the highlighted item.", 79, "w:\\4ed\\code\\4coder_lists.cpp", 28, 15 }, { PROC_LINKS(lister__write_character, 0), "lister__write_character", 23, "A lister mode command that dispatches to the lister's write character handler.", 78, "w:\\4ed\\code\\4coder_lists.cpp", 28, 30 }, @@ -397,10 +397,10 @@ static Command_Metadata fcoder_metacmd_table[233] = { { PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\4coder_lists.cpp", 28, 854 }, { PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\4coder_lists.cpp", 28, 887 }, { PROC_LINKS(command_lister, 0), "command_lister", 14, "Opens an interactive list of all registered commands.", 53, "w:\\4ed\\code\\4coder_lists.cpp", 28, 969 }, -{ PROC_LINKS(auto_tab_whole_file, 0), "auto_tab_whole_file", 19, "Audo-indents the entire current buffer.", 39, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 530 }, -{ PROC_LINKS(auto_tab_line_at_cursor, 0), "auto_tab_line_at_cursor", 23, "Auto-indents the line on which the cursor sits.", 47, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 539 }, -{ PROC_LINKS(auto_tab_range, 0), "auto_tab_range", 14, "Auto-indents the range between the cursor and the mark.", 55, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 549 }, -{ PROC_LINKS(write_and_auto_tab, 0), "write_and_auto_tab", 18, "Inserts a character and auto-indents the line on which the cursor sits.", 71, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 559 }, +{ PROC_LINKS(auto_tab_whole_file, 0), "auto_tab_whole_file", 19, "Audo-indents the entire current buffer.", 39, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 526 }, +{ PROC_LINKS(auto_tab_line_at_cursor, 0), "auto_tab_line_at_cursor", 23, "Auto-indents the line on which the cursor sits.", 47, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 535 }, +{ PROC_LINKS(auto_tab_range, 0), "auto_tab_range", 14, "Auto-indents the range between the cursor and the mark.", 55, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 545 }, +{ PROC_LINKS(write_and_auto_tab, 0), "write_and_auto_tab", 18, "Inserts a character and auto-indents the line on which the cursor sits.", 71, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 555 }, { PROC_LINKS(list_all_locations, 0), "list_all_locations", 18, "Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.", 99, "w:\\4ed\\code\\4coder_search.cpp", 29, 166 }, { PROC_LINKS(list_all_substring_locations, 0), "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "w:\\4ed\\code\\4coder_search.cpp", 29, 172 }, { PROC_LINKS(list_all_locations_case_insensitive, 0), "list_all_locations_case_insensitive", 35, "Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.", 101, "w:\\4ed\\code\\4coder_search.cpp", 29, 178 }, @@ -412,28 +412,28 @@ static Command_Metadata fcoder_metacmd_table[233] = { { PROC_LINKS(list_all_locations_of_type_definition, 0), "list_all_locations_of_type_definition", 37, "Queries user for string, lists all locations of strings that appear to define a type whose name matches the input string.", 121, "w:\\4ed\\code\\4coder_search.cpp", 29, 214 }, { PROC_LINKS(list_all_locations_of_type_definition_of_identifier, 0), "list_all_locations_of_type_definition_of_identifier", 51, "Reads a token or word under the cursor and lists all locations of strings that appear to define a type whose name matches it.", 125, "w:\\4ed\\code\\4coder_search.cpp", 29, 222 }, { PROC_LINKS(word_complete, 0), "word_complete", 13, "Iteratively tries completing the word to the left of the cursor with other words in open buffers that have the same prefix string.", 130, "w:\\4ed\\code\\4coder_search.cpp", 29, 376 }, -{ PROC_LINKS(goto_jump_at_cursor, 0), "goto_jump_at_cursor", 19, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 352 }, -{ PROC_LINKS(goto_jump_at_cursor_same_panel, 0), "goto_jump_at_cursor_same_panel", 30, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list.", 167, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 379 }, -{ PROC_LINKS(goto_next_jump, 0), "goto_next_jump", 14, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.", 123, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 468 }, -{ PROC_LINKS(goto_prev_jump, 0), "goto_prev_jump", 14, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations.", 127, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 485 }, -{ PROC_LINKS(goto_next_jump_no_skips, 0), "goto_next_jump_no_skips", 23, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.", 132, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 498 }, -{ PROC_LINKS(goto_prev_jump_no_skips, 0), "goto_prev_jump_no_skips", 23, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 515 }, -{ PROC_LINKS(goto_first_jump, 0), "goto_first_jump", 15, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 529 }, -{ PROC_LINKS(goto_first_jump_same_panel_sticky, 0), "goto_first_jump_same_panel_sticky", 33, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer and views the buffer in the panel where the jump list was.", 153, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 546 }, -{ PROC_LINKS(newline_or_goto_position, 0), "newline_or_goto_position", 24, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 568 }, -{ PROC_LINKS(newline_or_goto_position_same_panel, 0), "newline_or_goto_position_same_panel", 35, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 585 }, +{ PROC_LINKS(goto_jump_at_cursor, 0), "goto_jump_at_cursor", 19, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 353 }, +{ PROC_LINKS(goto_jump_at_cursor_same_panel, 0), "goto_jump_at_cursor_same_panel", 30, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list.", 167, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 380 }, +{ PROC_LINKS(goto_next_jump, 0), "goto_next_jump", 14, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.", 123, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 469 }, +{ PROC_LINKS(goto_prev_jump, 0), "goto_prev_jump", 14, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations.", 127, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 486 }, +{ PROC_LINKS(goto_next_jump_no_skips, 0), "goto_next_jump_no_skips", 23, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.", 132, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 499 }, +{ PROC_LINKS(goto_prev_jump_no_skips, 0), "goto_prev_jump_no_skips", 23, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 516 }, +{ PROC_LINKS(goto_first_jump, 0), "goto_first_jump", 15, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 530 }, +{ PROC_LINKS(goto_first_jump_same_panel_sticky, 0), "goto_first_jump_same_panel_sticky", 33, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer and views the buffer in the panel where the jump list was.", 153, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 547 }, +{ PROC_LINKS(newline_or_goto_position, 0), "newline_or_goto_position", 24, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 569 }, +{ PROC_LINKS(newline_or_goto_position_same_panel, 0), "newline_or_goto_position_same_panel", 35, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 586 }, { PROC_LINKS(view_jump_list_with_lister, 0), "view_jump_list_with_lister", 26, "When executed on a buffer with jumps, creates a persistent lister for all the jumps", 83, "w:\\4ed\\code\\4coder_jump_lister.cpp", 34, 104 }, { PROC_LINKS(log_graph__escape, 0), "log_graph__escape", 17, "Ends the log grapher", 20, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 906 }, -{ PROC_LINKS(log_graph__scroll_wheel, 0), "log_graph__scroll_wheel", 23, "Scrolls the log graph", 21, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 917 }, -{ PROC_LINKS(log_graph__page_up, 0), "log_graph__page_up", 18, "Scroll the log graph up one whole page", 38, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 928 }, -{ PROC_LINKS(log_graph__page_down, 0), "log_graph__page_down", 20, "Scroll the log graph down one whole page", 40, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 936 }, -{ PROC_LINKS(log_graph__click_select_event, 0), "log_graph__click_select_event", 29, "Select the event record at the mouse point in the log graph", 59, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 970 }, -{ PROC_LINKS(log_graph__click_jump_to_event_source, 0), "log_graph__click_jump_to_event_source", 37, "Jump to the code that logged the event record at the mouse point in the log graph", 81, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 989 }, -{ PROC_LINKS(show_the_log_graph, 0), "show_the_log_graph", 18, "Parser *log* and displays the 'log graph' UI", 44, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 1037 }, +{ PROC_LINKS(log_graph__scroll_wheel, 0), "log_graph__scroll_wheel", 23, "Scrolls the log graph", 21, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 915 }, +{ PROC_LINKS(log_graph__page_up, 0), "log_graph__page_up", 18, "Scroll the log graph up one whole page", 38, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 926 }, +{ PROC_LINKS(log_graph__page_down, 0), "log_graph__page_down", 20, "Scroll the log graph down one whole page", 40, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 934 }, +{ PROC_LINKS(log_graph__click_select_event, 0), "log_graph__click_select_event", 29, "Select the event record at the mouse point in the log graph", 59, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 968 }, +{ PROC_LINKS(log_graph__click_jump_to_event_source, 0), "log_graph__click_jump_to_event_source", 37, "Jump to the code that logged the event record at the mouse point in the log graph", 81, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 987 }, +{ PROC_LINKS(show_the_log_graph, 0), "show_the_log_graph", 18, "Parser *log* and displays the 'log graph' UI", 44, "w:\\4ed\\code\\4coder_log_parser.cpp", 33, 1035 }, { PROC_LINKS(copy, 0), "copy", 4, "Copy the text in the range from the cursor to the mark onto the clipboard.", 74, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 19 }, { PROC_LINKS(cut, 0), "cut", 3, "Cut the text in the range from the cursor to the mark onto the clipboard.", 73, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 28 }, { PROC_LINKS(paste, 0), "paste", 5, "At the cursor, insert the text at the top of the clipboard.", 59, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 39 }, -{ PROC_LINKS(paste_next, 0), "paste_next", 10, "If the previous command was paste or paste_next, replaces the paste range with the next text down on the clipboard, otherwise operates as the paste command.", 156, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 72 }, +{ PROC_LINKS(paste_next, 0), "paste_next", 10, "If the previous command was paste or paste_next, replaces the paste range with the next text down on the clipboard, otherwise operates as the paste command.", 156, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 73 }, { PROC_LINKS(paste_and_indent, 0), "paste_and_indent", 16, "Paste from the top of clipboard and run auto-indent on the newly pasted text.", 77, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 114 }, { PROC_LINKS(paste_next_and_indent, 0), "paste_next_and_indent", 21, "Paste the next item on the clipboard and run auto-indent on the newly pasted text.", 82, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 121 }, { PROC_LINKS(execute_previous_cli, 0), "execute_previous_cli", 20, "If the command execute_any_cli has already been used, this will execute a CLI reusing the most recent buffer name and command.", 126, "w:\\4ed\\code\\4coder_system_command.cpp", 37, 7 }, @@ -453,16 +453,16 @@ static Command_Metadata fcoder_metacmd_table[233] = { { PROC_LINKS(setup_build_sh, 0), "setup_build_sh", 14, "Queries the user for several configuration options and initializes a new build shell script.", 92, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1319 }, { PROC_LINKS(setup_build_bat_and_sh, 0), "setup_build_bat_and_sh", 22, "Queries the user for several configuration options and initializes a new build batch script.", 92, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1325 }, { PROC_LINKS(project_command_lister, 0), "project_command_lister", 22, "Open a lister of all commands in the currently loaded project.", 62, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1340 }, -{ PROC_LINKS(list_all_functions_current_buffer, 0), "list_all_functions_current_buffer", 33, "Creates a jump list of lines of the current buffer that appear to define or declare functions.", 94, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 266 }, -{ PROC_LINKS(list_all_functions_current_buffer_lister, 0), "list_all_functions_current_buffer_lister", 40, "Creates a lister of locations that look like function definitions and declarations in the buffer.", 97, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 276 }, -{ PROC_LINKS(list_all_functions_all_buffers, 0), "list_all_functions_all_buffers", 30, "Creates a jump list of lines from all buffers that appear to define or declare functions.", 89, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 288 }, -{ PROC_LINKS(list_all_functions_all_buffers_lister, 0), "list_all_functions_all_buffers_lister", 37, "Creates a lister of locations that look like function definitions and declarations all buffers.", 95, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 294 }, -{ PROC_LINKS(select_surrounding_scope, 0), "select_surrounding_scope", 24, "Finds the scope enclosed by '{' '}' surrounding the cursor and puts the cursor and mark on the '{' and '}'.", 107, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 341 }, -{ PROC_LINKS(select_next_scope_absolute, 0), "select_next_scope_absolute", 26, "Finds the first scope started by '{' after the cursor and puts the cursor and mark on the '{' and '}'.", 102, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 356 }, -{ PROC_LINKS(select_prev_scope_absolute, 0), "select_prev_scope_absolute", 26, "Finds the first scope started by '{' before the cursor and puts the cursor and mark on the '{' and '}'.", 103, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 375 }, -{ PROC_LINKS(place_in_scope, 0), "place_in_scope", 14, "Wraps the code contained in the range between cursor and mark with a new curly brace scope.", 91, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 449 }, -{ PROC_LINKS(delete_current_scope, 0), "delete_current_scope", 20, "Deletes the braces surrounding the currently selected scope. Leaves the contents within the scope.", 99, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 455 }, -{ PROC_LINKS(scope_absorb_down, 0), "scope_absorb_down", 17, "If a scope is currently selected, and a statement or block statement is present below the current scope, the statement is moved into the scope.", 143, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 672 }, +{ PROC_LINKS(list_all_functions_current_buffer, 0), "list_all_functions_current_buffer", 33, "Creates a jump list of lines of the current buffer that appear to define or declare functions.", 94, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 276 }, +{ PROC_LINKS(list_all_functions_current_buffer_lister, 0), "list_all_functions_current_buffer_lister", 40, "Creates a lister of locations that look like function definitions and declarations in the buffer.", 97, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 286 }, +{ PROC_LINKS(list_all_functions_all_buffers, 0), "list_all_functions_all_buffers", 30, "Creates a jump list of lines from all buffers that appear to define or declare functions.", 89, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 298 }, +{ PROC_LINKS(list_all_functions_all_buffers_lister, 0), "list_all_functions_all_buffers_lister", 37, "Creates a lister of locations that look like function definitions and declarations all buffers.", 95, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 304 }, +{ PROC_LINKS(select_surrounding_scope, 0), "select_surrounding_scope", 24, "Finds the scope enclosed by '{' '}' surrounding the cursor and puts the cursor and mark on the '{' and '}'.", 107, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 352 }, +{ PROC_LINKS(select_next_scope_absolute, 0), "select_next_scope_absolute", 26, "Finds the first scope started by '{' after the cursor and puts the cursor and mark on the '{' and '}'.", 102, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 367 }, +{ PROC_LINKS(select_prev_scope_absolute, 0), "select_prev_scope_absolute", 26, "Finds the first scope started by '{' before the cursor and puts the cursor and mark on the '{' and '}'.", 103, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 386 }, +{ PROC_LINKS(place_in_scope, 0), "place_in_scope", 14, "Wraps the code contained in the range between cursor and mark with a new curly brace scope.", 91, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 460 }, +{ PROC_LINKS(delete_current_scope, 0), "delete_current_scope", 20, "Deletes the braces surrounding the currently selected scope. Leaves the contents within the scope.", 99, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 466 }, +{ PROC_LINKS(scope_absorb_down, 0), "scope_absorb_down", 17, "If a scope is currently selected, and a statement or block statement is present below the current scope, the statement is moved into the scope.", 143, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 698 }, { PROC_LINKS(open_long_braces, 0), "open_long_braces", 16, "At the cursor, insert a '{' and '}' separated by a blank line.", 62, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 46 }, { PROC_LINKS(open_long_braces_semicolon, 0), "open_long_braces_semicolon", 26, "At the cursor, insert a '{' and '};' separated by a blank line.", 63, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 54 }, { PROC_LINKS(open_long_braces_break, 0), "open_long_braces_break", 22, "At the cursor, insert a '{' and '}break;' separated by a blank line.", 68, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 62 }, @@ -485,8 +485,8 @@ static Command_Metadata fcoder_metacmd_table[233] = { { PROC_LINKS(miblo_decrement_time_stamp, 0), "miblo_decrement_time_stamp", 26, "Decrement a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 237 }, { PROC_LINKS(miblo_increment_time_stamp_minute, 0), "miblo_increment_time_stamp_minute", 33, "Increment a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 243 }, { PROC_LINKS(miblo_decrement_time_stamp_minute, 0), "miblo_decrement_time_stamp_minute", 33, "Decrement a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 249 }, -{ PROC_LINKS(rename_parameter, 0), "rename_parameter", 16, "If the cursor is found to be on the name of a function parameter in the signature of a function definition, all occurences within the scope of the function will be replaced with a new provided string.", 200, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 189 }, -{ PROC_LINKS(write_explicit_enum_values, 0), "write_explicit_enum_values", 26, "If the cursor is found to be on the '{' of an enum definition, the values of the enum will be filled in sequentially starting from zero. Existing values are overwritten.", 170, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 498 }, +{ PROC_LINKS(rename_parameter, 0), "rename_parameter", 16, "If the cursor is found to be on the name of a function parameter in the signature of a function definition, all occurences within the scope of the function will be replaced with a new provided string.", 200, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 187 }, +{ PROC_LINKS(write_explicit_enum_values, 0), "write_explicit_enum_values", 26, "If the cursor is found to be on the '{' of an enum definition, the values of the enum will be filled in sequentially starting from zero. Existing values are overwritten.", 170, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 496 }, }; static int32_t fcoder_metacmd_ID_write_explicit_enum_flags = 0; static int32_t fcoder_metacmd_ID_seek_beginning_of_textual_line = 1; diff --git a/4coder_helper.cpp b/4coder_helper.cpp index 79fe3f87..457e423a 100644 --- a/4coder_helper.cpp +++ b/4coder_helper.cpp @@ -4,6 +4,10 @@ // TOP +#define scope_attachment(app,S,I,T) ((T*)managed_scope_get_attachment((app), (S), (I), sizeof(T))) + +//////////////////////////////// + internal Binding_Unit* write_unit(Bind_Helper *helper, Binding_Unit unit){ Binding_Unit *p = 0; @@ -162,7 +166,7 @@ set_get_view_buffer_region_hook(Bind_Helper *helper, Get_View_Buffer_Region_Func } internal void -set_new_file_hook(Bind_Helper *helper, Open_File_Hook_Function *func){ +set_new_file_hook(Bind_Helper *helper, Buffer_Hook_Function *func){ Binding_Unit unit = {}; unit.type = unit_hook; unit.hook.hook_id = special_hook_new_file; @@ -180,7 +184,7 @@ set_start_hook(Bind_Helper *helper, Start_Hook_Function *func){ } internal void -set_open_file_hook(Bind_Helper *helper, Open_File_Hook_Function *func){ +set_open_file_hook(Bind_Helper *helper, Buffer_Hook_Function *func){ Binding_Unit unit = {}; unit.type = unit_hook; unit.hook.hook_id = special_hook_open_file; @@ -189,7 +193,7 @@ set_open_file_hook(Bind_Helper *helper, Open_File_Hook_Function *func){ } internal void -set_save_file_hook(Bind_Helper *helper, Open_File_Hook_Function *func){ +set_save_file_hook(Bind_Helper *helper, Buffer_Hook_Function *func){ Binding_Unit unit = {}; unit.type = unit_hook; unit.hook.hook_id = special_hook_save_file; @@ -198,7 +202,7 @@ set_save_file_hook(Bind_Helper *helper, Open_File_Hook_Function *func){ } internal void -set_end_file_hook(Bind_Helper *helper, Open_File_Hook_Function *func){ +set_end_file_hook(Bind_Helper *helper, Buffer_Hook_Function *func){ Binding_Unit unit = {}; unit.type = unit_hook; unit.hook.hook_id = special_hook_end_file; @@ -597,21 +601,25 @@ get_line_end_pos_from_pos(Application_Links *app, Buffer_ID buffer, i64 pos){ return(get_line_side_pos_from_pos(app, buffer, pos, Side_Max)); } -internal Cpp_Token* -get_first_token_from_pos(Cpp_Token_Array tokens, i64 pos){ - Cpp_Get_Token_Result get_token = cpp_get_token(tokens, (i32)pos); +internal Token* +get_first_token_from_pos(Token_Array tokens, i64 pos){ + NotImplemented; + Token *result = 0; +#if 0 + Get_Token_Result get_token = cpp_get_token(tokens, (i32)pos); if (get_token.in_whitespace_after_token){ get_token.token_index += 1; } - Cpp_Token *result = 0; + Token *result = 0; if (get_token.token_index < tokens.count){ result = tokens.tokens + get_token.token_index; } +#endif return(result); } -internal Cpp_Token* -get_first_token_from_line(Application_Links *app, Buffer_ID buffer, Cpp_Token_Array tokens, i64 line){ +internal Token* +get_first_token_from_line(Application_Links *app, Buffer_ID buffer, Token_Array tokens, i64 line){ i64 line_start = get_line_start_pos(app, buffer, line); return(get_first_token_from_pos(tokens, line_start)); } @@ -792,18 +800,20 @@ boundary_inside_quotes(Application_Links *app, Buffer_ID buffer, Side side, Scan internal i64 boundary_token(Application_Links *app, Buffer_ID buffer, Side side, Scan_Direction direction, i64 pos){ - i64 result = 0; + i64 result = boundary_non_whitespace(app, buffer, side, direction, pos); + NotImplemented; +#if 0 if (!buffer_tokens_are_ready(app, buffer)){ result = boundary_non_whitespace(app, buffer, side, direction, pos); } else{ - Cpp_Token_Array tokens = buffer_get_token_array(app, buffer); + Token_Array tokens = buffer_get_token_array(app, buffer); switch (direction){ case Scan_Forward: { i32 buffer_size = (i32)buffer_get_size(app, buffer); if (tokens.count > 0){ - Cpp_Token *token = get_first_token_from_pos(tokens, pos); + Token *token = get_first_token_from_pos(tokens, pos); if (token != 0){ if (side == Side_Max){ result = token->start + token->size; @@ -835,7 +845,7 @@ boundary_token(Application_Links *app, Buffer_ID buffer, Side side, Scan_Directi case Scan_Backward: { if (tokens.count > 0){ - Cpp_Token *token = get_first_token_from_pos(tokens, pos); + Token *token = get_first_token_from_pos(tokens, pos); if (side == Side_Min){ if (token == 0){ token = tokens.tokens + tokens.count - 1; @@ -881,7 +891,7 @@ boundary_token(Application_Links *app, Buffer_ID buffer, Side side, Scan_Directi }break; } } - +#endif return(result); } @@ -1191,8 +1201,8 @@ push_buffer_range(Application_Links *app, Arena *arena, Buffer_ID buffer, Range_ } internal String_Const_u8 -push_token_lexeme(Application_Links *app, Arena *arena, Buffer_ID buffer, Cpp_Token token){ - return(push_buffer_range(app, arena, buffer, Ii64(token.start, token.start + token.size))); +push_token_lexeme(Application_Links *app, Arena *arena, Buffer_ID buffer, Token token){ + return(push_buffer_range(app, arena, buffer, Ii64(token.pos, token.pos + token.size))); } internal String_Const_u8 @@ -1243,7 +1253,7 @@ buffer_get_char(Application_Links *app, Buffer_ID buffer_id, i64 pos){ } internal b32 -token_lexeme_string_match(Application_Links *app, Buffer_ID buffer, Cpp_Token token, String_Const_u8 b){ +token_lexeme_string_match(Application_Links *app, Buffer_ID buffer, Token token, String_Const_u8 b){ Scratch_Block scratch(app); return(string_match(push_token_lexeme(app, scratch, buffer, token), b)); } @@ -1727,16 +1737,6 @@ buffer_identifier_to_id_create_out_buffer(Application_Links *app, Buffer_Identif //////////////////////////////// -internal void -adjust_all_buffer_wrap_widths(Application_Links *app, i32 wrap_width, i32 min_base_width){ - for (Buffer_ID buffer = get_buffer_next(app, 0, AccessAll); - buffer != 0; - buffer = get_buffer_next(app, buffer, AccessAll)){ - buffer_set_setting(app, buffer, BufferSetting_WrapPosition, wrap_width); - buffer_set_setting(app, buffer, BufferSetting_MinimumBaseWrapPosition, min_base_width); - } -} - internal View_ID open_view(Application_Links *app, View_ID view_location, View_Split_Position position){ View_ID result = 0; @@ -1817,12 +1817,12 @@ view_open_file(Application_Links *app, View_ID view, String_Const_u8 file_name, internal void view_disable_highlight_range(Application_Links *app, View_ID view){ Managed_Scope scope = view_get_managed_scope(app, view); - Managed_Object highlight = 0; - if (managed_variable_get(app, scope, view_highlight_range, &highlight)){ - managed_object_free(app, highlight); + Managed_Object *highlight = scope_attachment(app, scope, view_highlight_range, Managed_Object); + if (*highlight != 0){ + managed_object_free(app, *highlight); } - managed_variable_set(app, scope, view_highlight_range, 0); - managed_variable_set(app, scope, view_highlight_buffer, 0); + managed_scope_attachment_erase(app, scope, view_highlight_range); + managed_scope_attachment_erase(app, scope, view_highlight_buffer); } internal void @@ -1831,13 +1831,14 @@ view_set_highlight_range(Application_Links *app, View_ID view, Range_i64 range){ Buffer_ID buffer = view_get_buffer(app, view, AccessAll); Managed_Scope scope = view_get_managed_scope(app, view); - Managed_Object highlight = alloc_buffer_markers_on_buffer(app, buffer, 2, &scope); - managed_variable_set(app, scope, view_highlight_range, highlight); + Managed_Object *highlight = scope_attachment(app, scope, view_highlight_range, Managed_Object); + *highlight = alloc_buffer_markers_on_buffer(app, buffer, 2, &scope); Marker markers[2] = {}; - markers[0].pos = (i32)range.min; - markers[1].pos = (i32)range.max; - managed_object_store_data(app, highlight, 0, 2, markers); - managed_variable_set(app, scope, view_highlight_buffer, buffer); + markers[0].pos = range.min; + markers[1].pos = range.max; + managed_object_store_data(app, *highlight, 0, 2, markers); + Buffer_ID *highlight_buffer = scope_attachment(app, scope, view_highlight_buffer, Buffer_ID); + *highlight_buffer = buffer; } //////////////////////////////// @@ -1873,212 +1874,130 @@ try_buffer_kill(Application_Links *app, Buffer_ID buffer, View_ID gui_view_id, B //////////////////////////////// -internal b32 -init_stream_chunk(Stream_Chunk *chunk, Application_Links *app, Buffer_ID buffer_id, - i32 pos, char *data, u32 size){ - b32 result = false; - - i32 buffer_size = (i32)buffer_get_size(app, buffer_id); - if (0 <= pos && pos < buffer_size && size > 0){ - chunk->app = app; - chunk->buffer_id = buffer_id; - chunk->base_data = data; - chunk->data_size = size; - chunk->start = round_down_i32(pos, size); - chunk->end = round_up_i32(pos, size); - - if (chunk->max_end > buffer_size || chunk->max_end == 0){ - chunk->max_end = buffer_size; - } - - if (chunk->max_end && chunk->max_end < chunk->end){ - chunk->end = chunk->max_end; - } - if (chunk->min_start && chunk->min_start > chunk->start){ - chunk->start = chunk->min_start; - } - - if (chunk->start < chunk->end){ - buffer_read_range(app, buffer_id, Ii64(chunk->start, chunk->end), chunk->base_data); - chunk->data = chunk->base_data - chunk->start; - result = true; - } - } - - return(result); -} - -internal b32 -forward_stream_chunk(Stream_Chunk *chunk){ - Application_Links *app = chunk->app; - Buffer_ID buffer_id = chunk->buffer_id; - b32 result = 0; - - i32 buffer_size = (i32)buffer_get_size(app, buffer_id); - if (chunk->end < buffer_size){ - chunk->start = chunk->end; - chunk->end += chunk->data_size; - - if (chunk->max_end && chunk->max_end < chunk->end){ - chunk->end = chunk->max_end; - } - if (chunk->min_start && chunk->min_start > chunk->start){ - chunk->start = chunk->min_start; - } - - if (chunk->start < chunk->end){ - buffer_read_range(app, buffer_id, Ii64(chunk->start, chunk->end), chunk->base_data); - chunk->data = chunk->base_data - chunk->start; - result = 1; - } - } - - else if (chunk->add_null && chunk->end + 1 < buffer_size){ - chunk->start = buffer_size; - chunk->end = buffer_size + 1; - chunk->base_data[0] = 0; - chunk->data = chunk->base_data - chunk->start; - result = 1; - } - - return(result); -} - -internal b32 -backward_stream_chunk(Stream_Chunk *chunk){ - Application_Links *app = chunk->app; - Buffer_ID buffer_id = chunk->buffer_id; - b32 result = false; - - if (chunk->start > 0){ - chunk->end = chunk->start; - chunk->start -= chunk->data_size; - - if (chunk->max_end && chunk->max_end < chunk->end){ - chunk->end = chunk->max_end; - } - if (chunk->min_start && chunk->min_start > chunk->start){ - chunk->start = chunk->min_start; - } - - if (chunk->start < chunk->end){ - buffer_read_range(app, buffer_id, Ii64(chunk->start, chunk->end), chunk->base_data); - chunk->data = chunk->base_data - chunk->start; - result = true; - } - } - - else if (chunk->add_null && chunk->start > -1){ - chunk->start = -1; - chunk->end = 0; - chunk->base_data[0] = 0; - chunk->data = chunk->base_data - chunk->start; - result = true; - } - - return(result); -} - -//////////////////////////////// - -internal Token_Range -buffer_get_token_range(Application_Links *app, Buffer_ID buffer){ - Cpp_Token_Array array = buffer_get_token_array(app, buffer); - Token_Range range = {}; - range.first = array.tokens; - range.one_past_last = array.tokens + array.count; - return(range); -} - internal Token_Iterator -make_token_iterator(Token_Range range, Cpp_Token *token){ - Token_Iterator iterator = {}; - if (range.first != 0 && range.one_past_last != 0){ - if (token == 0 || token < range.first){ - token = range.first; - } - if (token > range.one_past_last){ - token = range.one_past_last; - } - iterator.token = token; - iterator.range = range; - } +make_token_iter(Buffer_ID buffer, Token_Array array, Token *token){ + Token_Iterator iterator = {buffer, array.tokens, array.tokens + array.count, token}; return(iterator); } internal Token_Iterator -make_token_iterator(Token_Range range, i32 index){ - return(make_token_iterator(range, range.first + index)); -} -internal void -token_iterator_set(Token_Iterator *iterator, Cpp_Token *token){ - *iterator = make_token_iterator(iterator->range, token); -} - -internal Cpp_Token* -token_range_check(Token_Range range, Cpp_Token *token){ - if (token < range.first || range.one_past_last <= token){ - token = 0; +make_token_iter(Buffer_ID buffer, Token_Array array, i64 pos){ + i64 first = 0; + i64 one_past_last = array.count; + i64 token_index = 0; + for (;;){ + i64 i = (first + one_past_last)/2; + Token *token = array.tokens + i; + if (token->pos + token->size <= pos){ + first = i + 1; + } + else if (pos < token->pos){ + one_past_last = i; + } + else{ + token_index = i; + break; + } + if (first + 1 >= one_past_last){ + token_index = first; + break; + } } + return(make_token_iter(buffer, array, array.tokens + token_index)); +} + +internal Token* +token_iter_current(Token_Iterator *iter){ + return(iter->token); +} + +internal Token* +token_iter_next_all(Token_Iterator *iter){ + Token *token = iter->token + 1; + Token *one_past_last = iter->one_past_last; + if (token > one_past_last){ + token = one_past_last; + } + iter->token = token; return(token); } -internal Cpp_Token* -token_iterator_current(Token_Iterator *iterator){ - return(token_range_check(iterator->range, iterator->token)); -} - -internal i32 -token_iterator_current_index(Token_Iterator *iterator){ - i32 index = -1; - Cpp_Token *token = token_iterator_current(iterator); - if (token != 0 && iterator->range.first <= token && token <= iterator->range.one_past_last){ - index = (i32)(token - iterator->range.first); - } - return(index); -} - -internal Cpp_Token* -token_iterator_goto_next(Token_Iterator *iterator){ - Cpp_Token *token = iterator->token; - Cpp_Token *one_past_last = iterator->range.one_past_last; +internal Token* +token_iter_next_non_whitespace(Token_Iterator *iter){ + Token *token = iter->token; + Token *one_past_last = iter->one_past_last; for (token += 1; token < one_past_last; token += 1){ - if (token->type != CPP_TOKEN_COMMENT){ + if (token->kind != TokenBaseKind_Whitespace){ break; } } - Cpp_Token *result = token_range_check(iterator->range, token); - *iterator = make_token_iterator(iterator->range, token); - return(result); + if (token > one_past_last){ + token = one_past_last; + } + iter->token = token; + return(token); } -internal Cpp_Token* -token_iterator_goto_next_raw(Token_Iterator *iterator){ - Cpp_Token *result = token_range_check(iterator->range, iterator->token + 1); - *iterator = make_token_iterator(iterator->range, iterator->token + 1); - return(result); +internal Token* +token_iter_next(Token_Iterator *iter){ + Token *token = iter->token; + Token *one_past_last = iter->one_past_last; + for (token += 1; token < one_past_last; token += 1){ + if (token->kind != TokenBaseKind_Whitespace && + token->kind != TokenBaseKind_Comment){ + break; + } + } + if (token > one_past_last){ + token = one_past_last; + } + iter->token = token; + return(token); } -internal Cpp_Token* -token_iterator_goto_prev(Token_Iterator *iterator){ - Cpp_Token *token = iterator->token; - Cpp_Token *first = iterator->range.first; +internal Token* +token_iter_prev_all(Token_Iterator *iter){ + Token *token = iter->token - 1; + Token *first = iter->first; + if (token < first){ + token = first; + } + iter->token = token; + return(token); +} + +internal Token* +token_iter_prev_non_whitespace(Token_Iterator *iter){ + Token *token = iter->token; + Token *first = iter->first; for (token -= 1; token >= first; token -= 1){ - if (token->type != CPP_TOKEN_COMMENT){ + if (token->kind != TokenBaseKind_Whitespace){ break; } } - Cpp_Token *result = token_range_check(iterator->range, token); - *iterator = make_token_iterator(iterator->range, token); - return(result); + if (token < first){ + token = first; + } + iter->token = token; + return(token); } -internal Cpp_Token* -token_iterator_goto_prev_raw(Token_Iterator *iterator){ - Cpp_Token *result = token_range_check(iterator->range, iterator->token - 1); - *iterator = make_token_iterator(iterator->range, iterator->token - 1); - return(result); +internal Token* +token_iter_prev(Token_Iterator *iter){ + Token *token = iter->token; + Token *first = iter->first; + for (token -= 1; token >= first; token -= 1){ + if (token->kind != TokenBaseKind_Whitespace && + token->kind != TokenBaseKind_Comment){ + break; + } + } + if (token < first){ + token = first; + } + iter->token = token; + return(token); } //////////////////////////////// @@ -2098,18 +2017,23 @@ get_query_string(Application_Links *app, char *query_str, u8 *string_space, i32 internal b32 get_token_from_pos(Application_Links *app, Buffer_ID buffer, u64 pos, Cpp_Get_Token_Result *result){ b32 success = false; - Cpp_Token_Array array = buffer_get_token_array(app, buffer); + NotImplemented; +#if 0 + Token_Array array = buffer_get_token_array(app, buffer); if (array.count > 0){ success = true; *result = cpp_get_token(array, (i32)pos); } +#endif return(success); } internal String_Const_u8 push_token_or_word_under_pos(Application_Links *app, Arena *arena, Buffer_ID buffer, u64 pos){ String_Const_u8 result = {}; - Cpp_Get_Token_Result get_result = {}; + NotImplemented; +#if 0 + Get_Token_Result get_result = {}; b32 success = get_token_from_pos(app, buffer, (i32)pos, &get_result); if (success && !get_result.in_whitespace_after_token){ umem size = get_result.token_one_past_last - get_result.token_start; @@ -2117,6 +2041,7 @@ push_token_or_word_under_pos(Application_Links *app, Arena *arena, Buffer_ID buf result = push_buffer_range(app, arena, buffer, Ii64(get_result.token_start, get_result.token_one_past_last)); } } +#endif return(result); } @@ -2309,7 +2234,8 @@ get_ranges_of_duplicate_keys(Arena *arena, i32 *keys, i32 stride, i32 count){ internal void no_mark_snap_to_cursor(Application_Links *app, Managed_Scope view_scope){ - managed_variable_set(app, view_scope, view_snap_mark_to_cursor, false); + b32 *snap_to_cursor = scope_attachment(app, view_scope, view_snap_mark_to_cursor, b32); + *snap_to_cursor = false; } internal void @@ -2543,7 +2469,8 @@ get_dpi_scaling_value(Application_Links *app){ UI_QUIT_FUNCTION(ui_quit_clear_render_hook){ Managed_Scope scope = view_get_managed_scope(app, view); - managed_variable_set(app, scope, view_render_hook, 0); + View_Render_Hook **hook = scope_attachment(app, scope, view_render_hook, View_Render_Hook*); + *hook = 0; } //////////////////////////////// diff --git a/4coder_helper.h b/4coder_helper.h index 9d4a9ed6..f284ec3c 100644 --- a/4coder_helper.h +++ b/4coder_helper.h @@ -144,30 +144,11 @@ struct Indent_Info{ //////////////////////////////// -struct Stream_Chunk{ - Application_Links *app; - Buffer_ID buffer_id; - - char *base_data; - i32 start; - i32 end; - i32 min_start; - i32 max_end; - b32 add_null; - u32 data_size; - - char *data; -}; - -struct Token_Range{ - Cpp_Token *first; - Cpp_Token *one_past_last; -}; - struct Token_Iterator{ - // TODO(allen): source buffer - Cpp_Token *token; - Token_Range range; + Buffer_ID buffer; + Token *first; + Token *one_past_last; + Token *token; }; //////////////////////////////// diff --git a/4coder_jump_sticky.cpp b/4coder_jump_sticky.cpp index 525797f3..60dd464d 100644 --- a/4coder_jump_sticky.cpp +++ b/4coder_jump_sticky.cpp @@ -171,7 +171,8 @@ init_marker_list(Application_Links *app, Heap *heap, Buffer_ID buffer, Marker_Li Assert(managed_object_get_item_count(app, marker_handle) == total_jump_count); Assert(managed_object_get_type(app, marker_handle) == ManagedObjectType_Markers); - managed_variable_set(app, scope, sticky_jump_marker_handle, marker_handle); + Managed_Object *marker_handle_ptr = scope_attachment(app, scope, sticky_jump_marker_handle, Managed_Object); + *marker_handle_ptr = marker_handle; } Managed_Object stored_jump_array = alloc_managed_memory_in_scope(app, scope_array[0], sizeof(Sticky_Jump_Stored), jumps.count); @@ -280,10 +281,10 @@ get_jump_from_list(Application_Links *app, Marker_List *list, i32 index, ID_Pos_ scope_array[1] = buffer_get_managed_scope(app, target_buffer_id); Managed_Scope scope = get_managed_scope_with_multiple_dependencies(app, scope_array, ArrayCount(scope_array)); - Managed_Object marker_array = 0; - if (managed_variable_get(app, scope, sticky_jump_marker_handle, &marker_array)){ + Managed_Object *marker_array = scope_attachment(app, scope, sticky_jump_marker_handle, Managed_Object); + if (*marker_array != 0){ Marker marker = {}; - managed_object_load_data(app, marker_array, stored.index_into_marker_array, 1, &marker); + managed_object_load_data(app, *marker_array, stored.index_into_marker_array, 1, &marker); location->buffer_id = target_buffer_id; location->pos = marker.pos; result = true; @@ -603,8 +604,8 @@ CUSTOM_DOC("If the buffer in the active view is writable, inserts a character, o // End File Hook // -OPEN_FILE_HOOK_SIG(default_end_file); -OPEN_FILE_HOOK_SIG(end_file_close_jump_list){ +BUFFER_HOOK_SIG(default_end_file); +BUFFER_HOOK_SIG(end_file_close_jump_list){ Marker_List *list = get_marker_list_for_buffer(buffer_id); if (list != 0){ delete_marker_list(list); diff --git a/4coder_lib/4coder_heap.cpp b/4coder_lib/4coder_heap.cpp deleted file mode 100644 index 08168c35..00000000 --- a/4coder_lib/4coder_heap.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* -4coder_heap.cpp - Preversioning -no warranty implied; use at your own risk - -This software is in the public domain. Where that dedication is not -recognized, you are granted a perpetual, irrevocable license to copy, -distribute, and modify this file as you see fit. -*/ - -// TOP - -#define heap__sent_init(s) (s)->next=(s)->prev=(s) -#define heap__insert_next(p,n) ((n)->next=(p)->next,(n)->prev=(p),(n)->next->prev=(n),(p)->next=(n)) -#define heap__insert_prev(p,n) ((n)->prev=(p)->prev,(n)->next=(p),(n)->prev->next=(n),(p)->prev=(n)) -#define heap__remove(n) ((n)->next->prev=(n)->prev,(n)->prev->next=(n)->next) - -#if defined(DO_HEAP_CHECKS) -static void -heap_assert_good(Heap *heap){ - if (heap->in_order.next != 0){ - Assert(heap->in_order.prev != 0); - Assert(heap->free_nodes.next != 0); - Assert(heap->free_nodes.prev != 0); - for (Heap_Basic_Node *node = &heap->in_order;;){ - Assert(node->next->prev == node); - Assert(node->prev->next == node); - node = node->next; - if (node == &heap->in_order){ - break; - } - } - for (Heap_Basic_Node *node = &heap->free_nodes;;){ - Assert(node->next->prev == node); - Assert(node->prev->next == node); - node = node->next; - if (node == &heap->free_nodes){ - break; - } - } - } -} -#else -#define heap_assert_good(heap) ((void)(heap)) -#endif - -static void -heap_init(Heap *heap){ - heap__sent_init(&heap->in_order); - heap__sent_init(&heap->free_nodes); - heap->used_space = 0; - heap->total_space = 0; -} - -static void -heap_extend(Heap *heap, void *memory, i32 size){ - heap_assert_good(heap); - if (size >= sizeof(Heap_Node)){ - Heap_Node *new_node = (Heap_Node*)memory; - heap__insert_prev(&heap->in_order, &new_node->order); - heap__insert_next(&heap->free_nodes, &new_node->alloc); - new_node->size = size - sizeof(*new_node); - heap->total_space += (umem)size; - } - heap_assert_good(heap); -} - -static void* -heap__reserve_chunk(Heap *heap, Heap_Node *node, i32 size){ - u8 *ptr = (u8*)(node + 1); - i32 left_over_size = node->size - size; - if (left_over_size > sizeof(*node)){ - i32 new_node_size = left_over_size - sizeof(*node); - Heap_Node *new_node = (Heap_Node*)(ptr + size); - heap__insert_next(&node->order, &new_node->order); - heap__insert_next(&node->alloc, &new_node->alloc); - new_node->size = new_node_size; - } - heap__remove(&node->alloc); - node->alloc.next = 0; - node->alloc.prev = 0; - node->size = size; - heap->used_space += sizeof(*node) + size; - return(ptr); -} - -static void* -heap_allocate(Heap *heap, i32 size){ - if (heap->in_order.next != 0){ - heap_assert_good(heap); - i32 aligned_size = (size + sizeof(Heap_Node) - 1); - aligned_size = aligned_size - (aligned_size%sizeof(Heap_Node)); - for (Heap_Basic_Node *n = heap->free_nodes.next; - n != &heap->free_nodes; - n = n->next){ - Heap_Node *node = CastFromMember(Heap_Node, alloc, n); - if (node->size >= aligned_size){ - void *ptr = heap__reserve_chunk(heap, node, aligned_size); - heap_assert_good(heap); - return(ptr); - } - } - heap_assert_good(heap); - } - return(0); -} - -static void -heap__merge(Heap *heap, Heap_Node *l, Heap_Node *r){ - if (&l->order != &heap->in_order && &r->order != &heap->in_order && - l->alloc.next != 0 && l->alloc.prev != 0 && - r->alloc.next != 0 && r->alloc.prev != 0){ - u8 *ptr = (u8*)(l + 1) + l->size; - if (PtrDif(ptr, r) == 0){ - heap__remove(&r->order); - heap__remove(&r->alloc); - heap__remove(&l->alloc); - l->size += r->size + sizeof(*r); - heap__insert_next(&heap->free_nodes, &l->alloc); - } - } -} - -static void -heap_free(Heap *heap, void *memory){ - if (heap->in_order.next != 0 && memory != 0){ - Heap_Node *node = ((Heap_Node*)memory) - 1; - Assert(node->alloc.next == 0); - Assert(node->alloc.prev == 0); - heap->used_space -= sizeof(*node) + node->size; - heap_assert_good(heap); - heap__insert_next(&heap->free_nodes, &node->alloc); - heap_assert_good(heap); - heap__merge(heap, node, CastFromMember(Heap_Node, order, node->order.next)); - heap_assert_good(heap); - heap__merge(heap, CastFromMember(Heap_Node, order, node->order.prev), node); - heap_assert_good(heap); - } -} - -#define heap_array(g, T, size) (T*)heap_allocate(g, (i32)(sizeof(T)*(size))) - -// BOTTOM - diff --git a/4coder_lib/4coder_heap.h b/4coder_lib/4coder_heap.h deleted file mode 100644 index 451d625d..00000000 --- a/4coder_lib/4coder_heap.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -4coder_heap.h - Preversioning -no warranty implied; use at your own risk - -This software is in the public domain. Where that dedication is not -recognized, you are granted a perpetual, irrevocable license to copy, -distribute, and modify this file as you see fit. -*/ - -// TOP - -#if !defined(FCODER_HEAP_H) -#define FCODER_HEAP_H - -struct Heap_Basic_Node{ - Heap_Basic_Node *next; - Heap_Basic_Node *prev; -}; - -struct Heap_Node{ - union{ - struct{ - Heap_Basic_Node order; - Heap_Basic_Node alloc; - i32 size; - }; - u8 force_size__[64]; - }; -}; - -struct Heap{ - Heap_Basic_Node in_order; - Heap_Basic_Node free_nodes; - i32 used_space; - i32 total_space; -}; - -//#define DO_HEAP_CHECKS - -#endif - -// BOTTOM - diff --git a/4coder_lib/4coder_string.h b/4coder_lib/4coder_string.h deleted file mode 100644 index d2b3e572..00000000 --- a/4coder_lib/4coder_string.h +++ /dev/null @@ -1,2498 +0,0 @@ -/* -4coder_string.h - Version 1.0.121 -no warranty implied; use at your own risk - -This software is in the public domain. Where that dedication is not -recognized, you are granted a perpetual, irrevocable license to copy, -distribute, and modify this file as you see fit. - -To include implementation: #define FSTRING_IMPLEMENTATION -To use in C mode: #define FSTRING_C -*/ - -// TOP - -#if !defined(REMOVE_OLD_STRING) - -#if !defined(FSTRING_LINK) -# define FSTRING_LINK static -#endif - -#if !defined(FSTRING_INLINE) -# define FSTRING_INLINE static -#endif - -#if !defined(FSTRING_GUARD) -#define literal(s) (s), (sizeof(s) - 1) - -struct CString_Array{ - char **strings; - i32 count; -}; - -typedef struct String{ - char *str; - i32 size; - i32 memory_size; -} String; - -static String null_string = {}; -#endif - -#if !defined(FCODER_STRING_H) -#define FCODER_STRING_H - -FSTRING_INLINE b32 char_is_slash(char c); -FSTRING_INLINE b32 char_is_upper(char c); -FSTRING_INLINE b32 char_is_upper_utf8(char c); -FSTRING_INLINE b32 char_is_lower(char c); -FSTRING_INLINE b32 char_is_lower_utf8(u8 c); -FSTRING_INLINE char char_to_upper(char c); -FSTRING_INLINE char char_to_lower(char c); -FSTRING_INLINE b32 char_is_whitespace(char c); -FSTRING_INLINE b32 char_is_alpha_numeric(char c); -FSTRING_INLINE b32 char_is_alpha_numeric_utf8(u8 c); -FSTRING_INLINE b32 char_is_alpha_numeric_true(char c); -FSTRING_INLINE b32 char_is_alpha_numeric_true_utf8(u8 c); -FSTRING_INLINE b32 char_is_alpha(char c); -FSTRING_INLINE b32 char_is_alpha_utf8(u8 c); -FSTRING_INLINE b32 char_is_alpha_true(char c); -FSTRING_INLINE b32 char_is_alpha_true_utf8(u8 c); -FSTRING_INLINE b32 char_is_hex(char c); -FSTRING_INLINE b32 char_is_hex_utf8(u8 c); -FSTRING_INLINE b32 char_is_numeric(char c); -FSTRING_INLINE b32 char_is_numeric_utf8(u8 c); -FSTRING_INLINE String make_string_cap(void *str, i32 size, i32 mem_size); -FSTRING_INLINE String make_string(void *str, i32 size); -#ifndef make_lit_string -# define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s))) -#endif -#ifndef lit -# define lit(s) make_lit_string(s) -#endif -#ifndef make_fixed_width_string -# define make_fixed_width_string(s) (make_string_cap((char*)(s), 0, sizeof(s))) -#endif -#ifndef expand_str -# define expand_str(s) ((s).str), ((s).size) -#endif -FSTRING_LINK i32 str_size(char *str); -FSTRING_INLINE String make_string_slowly(void *str); -FSTRING_INLINE String substr_tail(String str, i32 start); -FSTRING_INLINE String substr(String str, i32 start, i32 size); -FSTRING_LINK String skip_whitespace(String str); -FSTRING_LINK String skip_whitespace_measure(String str, i32 *skip_length); -FSTRING_LINK String chop_whitespace(String str); -FSTRING_LINK String skip_chop_whitespace(String str); -FSTRING_LINK String skip_chop_whitespace_measure(String str, i32 *skip_length); -FSTRING_INLINE String tailstr(String str); -FSTRING_LINK b32 match_cc(char *a, char *b); -FSTRING_LINK b32 match_sc(String a, char *b); -FSTRING_INLINE b32 match_cs(char *a, String b); -FSTRING_LINK b32 match_ss(String a, String b); -FSTRING_LINK b32 match_part_ccl(char *a, char *b, i32 *len); -FSTRING_LINK b32 match_part_scl(String a, char *b, i32 *len); -FSTRING_INLINE b32 match_part_cc(char *a, char *b); -FSTRING_INLINE b32 match_part_sc(String a, char *b); -FSTRING_LINK b32 match_part_cs(char *a, String b); -FSTRING_LINK b32 match_part_ss(String a, String b); -FSTRING_LINK b32 match_insensitive_cc(char *a, char *b); -FSTRING_LINK b32 match_insensitive_sc(String a, char *b); -FSTRING_INLINE b32 match_insensitive_cs(char *a, String b); -FSTRING_LINK b32 match_insensitive_ss(String a, String b); -FSTRING_LINK b32 match_part_insensitive_ccl(char *a, char *b, i32 *len); -FSTRING_LINK b32 match_part_insensitive_scl(String a, char *b, i32 *len); -FSTRING_INLINE b32 match_part_insensitive_cc(char *a, char *b); -FSTRING_INLINE b32 match_part_insensitive_sc(String a, char *b); -FSTRING_LINK b32 match_part_insensitive_cs(char *a, String b); -FSTRING_LINK b32 match_part_insensitive_ss(String a, String b); -FSTRING_LINK i32 compare_cc(char *a, char *b); -FSTRING_LINK i32 compare_sc(String a, char *b); -FSTRING_INLINE i32 compare_cs(char *a, String b); -FSTRING_LINK i32 compare_ss(String a, String b); -FSTRING_LINK i32 find_c_char(char *str, i32 start, char character); -FSTRING_LINK i32 find_s_char(String str, i32 start, char character); -FSTRING_LINK i32 rfind_s_char(String str, i32 start, char character); -FSTRING_LINK i32 find_c_chars(char *str, i32 start, char *characters); -FSTRING_LINK i32 find_s_chars(String str, i32 start, char *characters); -FSTRING_LINK i32 find_substr_c(char *str, i32 start, String seek); -FSTRING_LINK i32 find_substr_s(String str, i32 start, String seek); -FSTRING_LINK i32 rfind_substr_s(String str, i32 start, String seek); -FSTRING_LINK i32 find_substr_insensitive_c(char *str, i32 start, String seek); -FSTRING_LINK i32 find_substr_insensitive_s(String str, i32 start, String seek); -FSTRING_INLINE b32 has_substr_c(char *s, String seek); -FSTRING_INLINE b32 has_substr_s(String s, String seek); -FSTRING_INLINE b32 has_substr_insensitive_c(char *s, String seek); -FSTRING_INLINE b32 has_substr_insensitive_s(String s, String seek); -FSTRING_LINK i32 copy_fast_unsafe_cc(char *dest, char *src); -FSTRING_LINK i32 copy_fast_unsafe_cs(char *dest, String src); -FSTRING_LINK b32 copy_checked_ss(String *dest, String src); -FSTRING_LINK b32 copy_checked_cs(char *dest, i32 dest_cap, String src); -FSTRING_LINK b32 copy_partial_sc(String *dest, char *src); -FSTRING_LINK b32 copy_partial_ss(String *dest, String src); -FSTRING_LINK b32 copy_partial_cs(char *dest, i32 dest_cap, String src); -FSTRING_INLINE i32 copy_cc(char *dest, char *src); -FSTRING_INLINE void copy_ss(String *dest, String src); -FSTRING_INLINE void copy_sc(String *dest, char *src); -FSTRING_LINK b32 append_checked_ss(String *dest, String src); -FSTRING_LINK b32 append_partial_sc(String *dest, char *src); -FSTRING_LINK b32 append_partial_ss(String *dest, String src); -FSTRING_LINK b32 append_s_char(String *dest, char c); -FSTRING_INLINE b32 append_ss(String *dest, String src); -FSTRING_INLINE b32 append_sc(String *dest, char *src); -FSTRING_LINK b32 terminate_with_null(String *str); -FSTRING_LINK b32 append_padding(String *dest, char c, i32 target_size); -FSTRING_LINK void string_interpret_escapes(String src, char *dst); -FSTRING_LINK void replace_char(String *str, char replace, char with); -FSTRING_LINK void replace_str_ss(String *str, String replace, String with); -FSTRING_LINK void replace_str_sc(String *str, String replace, char *with); -FSTRING_LINK void replace_str_cs(String *str, char *replace, String with); -FSTRING_LINK void replace_str_cc(String *str, char *replace, char *with); -FSTRING_LINK void to_lower_cc(char *src, char *dst); -FSTRING_LINK void to_lower_ss(String *dst, String src); -FSTRING_LINK void to_lower_s(String *str); -FSTRING_LINK void to_upper_cc(char *src, char *dst); -FSTRING_LINK void to_upper_ss(String *dst, String src); -FSTRING_LINK void to_upper_s(String *str); -FSTRING_LINK void to_camel_cc(char *src, char *dst); -FSTRING_LINK i32 int_to_str_size(i32 x); -FSTRING_LINK b32 int_to_str(String *dest, i32 x); -FSTRING_LINK b32 append_int_to_str(String *dest, i32 x); -FSTRING_LINK i32 u64_to_str_size(uint64_t x); -FSTRING_LINK b32 u64_to_str(String *dest, uint64_t x); -FSTRING_LINK b32 append_u64_to_str(String *dest, uint64_t x); -FSTRING_LINK i32 float_to_str_size(float x); -FSTRING_LINK b32 append_float_to_str(String *dest, float x); -FSTRING_LINK b32 float_to_str(String *dest, float x); -FSTRING_LINK i32 str_is_int_c(char *str); -FSTRING_LINK b32 str_is_int_s(String str); -FSTRING_LINK i32 str_to_int_c(char *str); -FSTRING_LINK i32 str_to_int_s(String str); -FSTRING_LINK i32 hexchar_to_int(char c); -FSTRING_LINK char int_to_hexchar(i32 x); -FSTRING_LINK u32 hexstr_to_int(String str); -FSTRING_LINK b32 color_to_hexstr(String *s, u32 color); -FSTRING_LINK b32 hexstr_to_color(String s, u32 *out); -FSTRING_LINK i32 reverse_seek_slash_pos(String str, i32 pos); -FSTRING_INLINE i32 reverse_seek_slash(String str); -FSTRING_INLINE String front_of_directory(String dir); -FSTRING_INLINE String path_of_directory(String dir); -FSTRING_LINK b32 set_last_folder_sc(String *dir, char *folder_name, char slash); -FSTRING_LINK b32 set_last_folder_ss(String *dir, String folder_name, char slash); -FSTRING_LINK String file_extension(String str); -FSTRING_LINK b32 remove_extension(String *str); -FSTRING_LINK b32 remove_last_folder(String *str); -FSTRING_LINK b32 string_set_match_table(void *str_set, i32 item_size, i32 count, String str, i32 *match_index); -FSTRING_LINK b32 string_set_match(String *str_set, i32 count, String str, i32 *match_index); -FSTRING_LINK String get_first_double_line(String source); -FSTRING_LINK String get_next_double_line(String source, String line); -FSTRING_LINK String get_next_word(String source, String prev_word); -FSTRING_LINK String get_first_word(String source); -FSTRING_LINK String string_push(Cursor *cursor, i32 size); -FSTRING_LINK String string_push_copy(Cursor *cursor, String str); -FSTRING_LINK String string_push(Arena *arena, i32 size); -FSTRING_LINK String string_push_copy(Arena *arena, String str); -FSTRING_LINK char* get_null_terminated(Arena *arena, String str); - -#endif - -#if !defined(FSTRING_C) && !defined(FSTRING_GUARD) - -FSTRING_INLINE String make_string(void *str, i32 size, i32 mem_size){return(make_string_cap(str,size,mem_size));} -FSTRING_INLINE String substr(String str, i32 start){return(substr_tail(str,start));} -FSTRING_LINK String skip_whitespace(String str, i32 *skip_length){return(skip_whitespace_measure(str,skip_length));} -FSTRING_LINK String skip_chop_whitespace(String str, i32 *skip_length){return(skip_chop_whitespace_measure(str,skip_length));} -FSTRING_LINK b32 match(char *a, char *b){return(match_cc(a,b));} -FSTRING_LINK b32 match(String a, char *b){return(match_sc(a,b));} -FSTRING_INLINE b32 match(char *a, String b){return(match_cs(a,b));} -FSTRING_LINK b32 match(String a, String b){return(match_ss(a,b));} -FSTRING_LINK b32 match_part(char *a, char *b, i32 *len){return(match_part_ccl(a,b,len));} -FSTRING_LINK b32 match_part(String a, char *b, i32 *len){return(match_part_scl(a,b,len));} -FSTRING_INLINE b32 match_part(char *a, char *b){return(match_part_cc(a,b));} -FSTRING_INLINE b32 match_part(String a, char *b){return(match_part_sc(a,b));} -FSTRING_LINK b32 match_part(char *a, String b){return(match_part_cs(a,b));} -FSTRING_LINK b32 match_part(String a, String b){return(match_part_ss(a,b));} -FSTRING_LINK b32 match_insensitive(char *a, char *b){return(match_insensitive_cc(a,b));} -FSTRING_LINK b32 match_insensitive(String a, char *b){return(match_insensitive_sc(a,b));} -FSTRING_INLINE b32 match_insensitive(char *a, String b){return(match_insensitive_cs(a,b));} -FSTRING_LINK b32 match_insensitive(String a, String b){return(match_insensitive_ss(a,b));} -FSTRING_LINK b32 match_part_insensitive(char *a, char *b, i32 *len){return(match_part_insensitive_ccl(a,b,len));} -FSTRING_LINK b32 match_part_insensitive(String a, char *b, i32 *len){return(match_part_insensitive_scl(a,b,len));} -FSTRING_INLINE b32 match_part_insensitive(char *a, char *b){return(match_part_insensitive_cc(a,b));} -FSTRING_INLINE b32 match_part_insensitive(String a, char *b){return(match_part_insensitive_sc(a,b));} -FSTRING_LINK b32 match_part_insensitive(char *a, String b){return(match_part_insensitive_cs(a,b));} -FSTRING_LINK b32 match_part_insensitive(String a, String b){return(match_part_insensitive_ss(a,b));} -FSTRING_LINK i32 compare(char *a, char *b){return(compare_cc(a,b));} -FSTRING_LINK i32 compare(String a, char *b){return(compare_sc(a,b));} -FSTRING_INLINE i32 compare(char *a, String b){return(compare_cs(a,b));} -FSTRING_LINK i32 compare(String a, String b){return(compare_ss(a,b));} -FSTRING_LINK i32 find(char *str, i32 start, char character){return(find_c_char(str,start,character));} -FSTRING_LINK i32 find(String str, i32 start, char character){return(find_s_char(str,start,character));} -FSTRING_LINK i32 rfind(String str, i32 start, char character){return(rfind_s_char(str,start,character));} -FSTRING_LINK i32 find(char *str, i32 start, char *characters){return(find_c_chars(str,start,characters));} -FSTRING_LINK i32 find(String str, i32 start, char *characters){return(find_s_chars(str,start,characters));} -FSTRING_LINK i32 find_substr(char *str, i32 start, String seek){return(find_substr_c(str,start,seek));} -FSTRING_LINK i32 find_substr(String str, i32 start, String seek){return(find_substr_s(str,start,seek));} -FSTRING_LINK i32 rfind_substr(String str, i32 start, String seek){return(rfind_substr_s(str,start,seek));} -FSTRING_LINK i32 find_substr_insensitive(char *str, i32 start, String seek){return(find_substr_insensitive_c(str,start,seek));} -FSTRING_LINK i32 find_substr_insensitive(String str, i32 start, String seek){return(find_substr_insensitive_s(str,start,seek));} -FSTRING_INLINE b32 has_substr(char *s, String seek){return(has_substr_c(s,seek));} -FSTRING_INLINE b32 has_substr(String s, String seek){return(has_substr_s(s,seek));} -FSTRING_INLINE b32 has_substr_insensitive(char *s, String seek){return(has_substr_insensitive_c(s,seek));} -FSTRING_INLINE b32 has_substr_insensitive(String s, String seek){return(has_substr_insensitive_s(s,seek));} -FSTRING_LINK i32 copy_fast_unsafe(char *dest, char *src){return(copy_fast_unsafe_cc(dest,src));} -FSTRING_LINK i32 copy_fast_unsafe(char *dest, String src){return(copy_fast_unsafe_cs(dest,src));} -FSTRING_LINK b32 copy_checked(String *dest, String src){return(copy_checked_ss(dest,src));} -FSTRING_LINK b32 copy_checked(char *dest, i32 dest_cap, String src){return(copy_checked_cs(dest,dest_cap,src));} -FSTRING_LINK b32 copy_partial(String *dest, char *src){return(copy_partial_sc(dest,src));} -FSTRING_LINK b32 copy_partial(String *dest, String src){return(copy_partial_ss(dest,src));} -FSTRING_LINK b32 copy_partial(char *dest, i32 dest_cap, String src){return(copy_partial_cs(dest,dest_cap,src));} -FSTRING_INLINE i32 copy(char *dest, char *src){return(copy_cc(dest,src));} -FSTRING_INLINE void copy(String *dest, String src){return(copy_ss(dest,src));} -FSTRING_INLINE void copy(String *dest, char *src){return(copy_sc(dest,src));} -FSTRING_LINK b32 append_checked(String *dest, String src){return(append_checked_ss(dest,src));} -FSTRING_LINK b32 append_partial(String *dest, char *src){return(append_partial_sc(dest,src));} -FSTRING_LINK b32 append_partial(String *dest, String src){return(append_partial_ss(dest,src));} -FSTRING_LINK b32 append(String *dest, char c){return(append_s_char(dest,c));} -FSTRING_INLINE b32 append(String *dest, String src){return(append_ss(dest,src));} -FSTRING_INLINE b32 append(String *dest, char *src){return(append_sc(dest,src));} -FSTRING_LINK void replace_str(String *str, String replace, String with){return(replace_str_ss(str,replace,with));} -FSTRING_LINK void replace_str(String *str, String replace, char *with){return(replace_str_sc(str,replace,with));} -FSTRING_LINK void replace_str(String *str, char *replace, String with){return(replace_str_cs(str,replace,with));} -FSTRING_LINK void replace_str(String *str, char *replace, char *with){return(replace_str_cc(str,replace,with));} -FSTRING_LINK void to_lower(char *src, char *dst){return(to_lower_cc(src,dst));} -FSTRING_LINK void to_lower(String *dst, String src){return(to_lower_ss(dst,src));} -FSTRING_LINK void to_lower(String *str){return(to_lower_s(str));} -FSTRING_LINK void to_upper(char *src, char *dst){return(to_upper_cc(src,dst));} -FSTRING_LINK void to_upper(String *dst, String src){return(to_upper_ss(dst,src));} -FSTRING_LINK void to_upper(String *str){return(to_upper_s(str));} -FSTRING_LINK void to_camel(char *src, char *dst){return(to_camel_cc(src,dst));} -FSTRING_LINK i32 str_is_int(char *str){return(str_is_int_c(str));} -FSTRING_LINK b32 str_is_int(String str){return(str_is_int_s(str));} -FSTRING_LINK i32 str_to_int(char *str){return(str_to_int_c(str));} -FSTRING_LINK i32 str_to_int(String str){return(str_to_int_s(str));} -FSTRING_LINK i32 reverse_seek_slash(String str, i32 pos){return(reverse_seek_slash_pos(str,pos));} -FSTRING_LINK b32 set_last_folder(String *dir, char *folder_name, char slash){return(set_last_folder_sc(dir,folder_name,slash));} -FSTRING_LINK b32 set_last_folder(String *dir, String folder_name, char slash){return(set_last_folder_ss(dir,folder_name,slash));} -FSTRING_LINK b32 string_set_match(void *str_set, i32 item_size, i32 count, String str, i32 *match_index){return(string_set_match_table(str_set,item_size,count,str,match_index));} - -#endif - - -// -// Character Helpers -// - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_slash(char c) -{ - return (c == '\\' || c == '/'); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_upper(char c) -{ - return (c >= 'A' && c <= 'Z'); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_upper_utf8(char c) -{ - return ((c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_lower(char c) -{ - return (c >= 'a' && c <= 'z'); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_lower_utf8(u8 c) -{ - return ((c >= 'a' && c <= 'z') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE char -char_to_upper(char c) -{ - return (c >= 'a' && c <= 'z') ? c + (char)('A' - 'a') : c; -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE char -char_to_lower(char c) -{ - return (c >= 'A' && c <= 'Z') ? c - (char)('A' - 'a') : c; -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_whitespace(char c) -{ - return (c == ' ' || c == '\n' || c == '\r' || c == '\t'); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_alpha_numeric(char c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_alpha_numeric_utf8(u8 c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_alpha_numeric_true(char c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_alpha_numeric_true_utf8(u8 c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_alpha(char c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_alpha_utf8(u8 c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_alpha_true(char c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_alpha_true_utf8(u8 c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_hex(char c) -{ - return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_hex_utf8(u8 c) -{ - return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_numeric(char c) -{ - return (c >= '0' && c <= '9'); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -char_is_numeric_utf8(u8 c) -{ - return ((c >= '0' && c <= '9') || (unsigned char)c >= 128); -} -#endif - - -// -// String Making Functions -// - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE String -make_string_cap(void *str, i32 size, i32 mem_size){ - String result; - result.str = (char*)str; - result.size = size; - result.memory_size = mem_size; - return(result); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE String -make_string(void *str, i32 size){ - return(make_string(str, size, size)); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -str_size(char *str) -{ - i32 i = 0; - if (str != 0){ - for (;str[i];++i); - } - return(i); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE String -make_string_slowly(void *str) -{ - String result; - result.str = (char*)str; - result.size = str_size((char*)str); - result.memory_size = result.size + 1; - return(result); -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE String -substr_tail(String str, i32 start) -{ - String result; - result.str = str.str + start; - result.size = str.size - start; - result.memory_size = 0; - return(result); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE String -substr(String str, i32 start, i32 size) -{ - String result; - result.str = str.str + start; - result.size = size; - if (start + size > str.size){ - result.size = str.size - start; - } - result.memory_size = 0; - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -skip_whitespace(String str) -{ - String result = {}; - i32 i = 0; - for (; i < str.size && char_is_whitespace(str.str[i]); ++i); - result = substr(str, i, str.size - i); - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -skip_whitespace_measure(String str, i32 *skip_length) -{ - String result = {}; - i32 i = 0; - for (; i < str.size && char_is_whitespace(str.str[i]); ++i); - result = substr(str, i, str.size - i); - *skip_length = i; - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -chop_whitespace(String str) -{ - String result = {}; - i32 i = str.size; - for (; i > 0 && char_is_whitespace(str.str[i-1]); --i); - result = substr(str, 0, i); - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -skip_chop_whitespace(String str) -{ - str = skip_whitespace(str); - str = chop_whitespace(str); - return(str); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -skip_chop_whitespace_measure(String str, i32 *skip_length) -{ - str = skip_whitespace_measure(str, skip_length); - str = chop_whitespace(str); - return(str); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE String -tailstr(String str) -{ - String result; - result.str = str.str + str.size; - result.memory_size = str.memory_size - str.size; - result.size = 0; - return(result); -} -#endif - - -// -// String Comparison -// - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_cc(char *a, char *b){ - for (i32 i = 0;; ++i){ - if (a[i] != b[i]){ - return 0; - } - if (a[i] == 0){ - return 1; - } - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_sc(String a, char *b){ - i32 i = 0; - for (; i < a.size; ++i){ - if (a.str[i] != b[i]){ - return 0; - } - } - if (b[i] != 0){ - return 0; - } - return 1; -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -match_cs(char *a, String b){ - return(match_sc(b,a)); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_ss(String a, String b){ - if (a.size != b.size){ - return 0; - } - for (i32 i = 0; i < b.size; ++i){ - if (a.str[i] != b.str[i]){ - return 0; - } - } - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_part_ccl(char *a, char *b, i32 *len){ - if (a == 0){ - a = ""; - } - if (b == 0){ - b = ""; - } - - i32 i; - for (i = 0; b[i] != 0; ++i){ - if (a[i] != b[i]){ - return(0); - } - } - *len = i; - return(1); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_part_scl(String a, char *b, i32 *len){ - if (b == 0){ - b = ""; - } - i32 i; - for (i = 0; b[i] != 0; ++i){ - if (i == a.size || a.str[i] != b[i]){ - return(0); - } - } - *len = i; - return(1); -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -match_part_cc(char *a, char *b){ - i32 x; - return match_part_ccl(a,b,&x); -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -match_part_sc(String a, char *b){ - i32 x; - return match_part_scl(a,b,&x); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_part_cs(char *a, String b){ - for (i32 i = 0; i != b.size; ++i){ - if (a[i] != b.str[i]){ - return 0; - } - } - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_part_ss(String a, String b){ - if (a.size < b.size){ - return(0); - } - for (i32 i = 0; i < b.size; ++i){ - if (a.str[i] != b.str[i]){ - return(0); - } - } - return(1); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_insensitive_cc(char *a, char *b){ - for (i32 i = 0;; ++i){ - if (char_to_upper(a[i]) != - char_to_upper(b[i])){ - return 0; - } - if (a[i] == 0){ - return 1; - } - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_insensitive_sc(String a, char *b){ - i32 i = 0; - for (; i < a.size; ++i){ - if (char_to_upper(a.str[i]) != - char_to_upper(b[i])){ - return 0; - } - } - if (b[i] != 0){ - return 0; - } - return 1; -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -match_insensitive_cs(char *a, String b){ - return match_insensitive_sc(b,a); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_insensitive_ss(String a, String b){ - if (a.size != b.size){ - return 0; - } - for (i32 i = 0; i < b.size; ++i){ - if (char_to_upper(a.str[i]) != - char_to_upper(b.str[i])){ - return 0; - } - } - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_part_insensitive_ccl(char *a, char *b, i32 *len){ - i32 i; - for (i = 0; b[i] != 0; ++i){ - if (char_to_upper(a[i]) != char_to_upper(b[i])){ - return 0; - } - } - *len = i; - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_part_insensitive_scl(String a, char *b, i32 *len){ - i32 i; - for (i = 0; b[i] != 0; ++i){ - if (char_to_upper(a.str[i]) != char_to_upper(b[i]) || - i == a.size){ - return 0; - } - } - *len = i; - return 1; -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -match_part_insensitive_cc(char *a, char *b){ - i32 x; - return match_part_insensitive_ccl(a,b,&x); -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -match_part_insensitive_sc(String a, char *b){ - i32 x; - return match_part_insensitive_scl(a,b,&x); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_part_insensitive_cs(char *a, String b){ - for (i32 i = 0; i != b.size; ++i){ - if (char_to_upper(a[i]) != char_to_upper(b.str[i])){ - return(0); - } - } - return(1); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -match_part_insensitive_ss(String a, String b){ - if (a.size < b.size){ - return(0); - } - for (i32 i = 0; i < b.size; ++i){ - if (char_to_upper(a.str[i]) != char_to_upper(b.str[i])){ - return(0); - } - } - return(1); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -compare_cc(char *a, char *b){ - i32 i = 0, r = 0; - while (a[i] == b[i] && a[i] != 0){ - ++i; - } - r = (a[i] > b[i]) - (a[i] < b[i]); - return(r); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -compare_sc(String a, char *b){ - i32 i = 0, r = 0; - while (i < a.size && a.str[i] == b[i]){ - ++i; - } - if (i < a.size){ - r = (a.str[i] > b[i]) - (a.str[i] < b[i]); - } - else{ - if (b[i] == 0){ - r = 0; - } - else{ - r = -1; - } - } - return(r); -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE i32 -compare_cs(char *a, String b){ - i32 r = -compare_sc(b,a); - return(r); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -compare_ss(String a, String b){ - i32 i = 0, r = 0; - i32 m = a.size; - if (b.size < m){ - m = b.size; - } - while (i < m && a.str[i] == b.str[i]){ - ++i; - } - - if (i < m){ - r = (a.str[i] > b.str[i]) - (b.str[i] > a.str[i]); - } - else{ - r = (a.size > b.size) - (b.size > a.size); - } - - return(r); -} -#endif - -// -// Finding Characters and Substrings -// - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -find_c_char(char *str, i32 start, char character){ - i32 i = start; - while (str[i] != character && str[i] != 0) ++i; - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -find_s_char(String str, i32 start, char character){ - i32 i = start; - while (i < str.size && str.str[i] != character) ++i; - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -rfind_s_char(String str, i32 start, char character){ - i32 i = start; - while (i >= 0 && str.str[i] != character) --i; - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -find_c_chars(char *str, i32 start, char *characters){ - i32 i = start, j; - while (str[i] != 0){ - for (j = 0; characters[j]; ++j){ - if (str[i] == characters[j]){ - return(i); - } - } - ++i; - } - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -find_s_chars(String str, i32 start, char *characters){ - i32 i = start, j; - while (i < str.size){ - for (j = 0; characters[j]; ++j){ - if (str.str[i] == characters[j]){ - return(i); - } - } - ++i; - } - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -find_substr_c(char *str, i32 start, String seek){ - i32 i, j, k; - b32 hit; - - if (seek.size == 0){ - i = str_size(str); - return(i); - } - for (i = start; str[i]; ++i){ - if (str[i] == seek.str[0]){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - if (str[k] != seek.str[j]){ - hit = 0; - break; - } - } - if (hit){ - return(i); - } - } - } - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -find_substr_s(String str, i32 start, String seek){ - i32 stop_at, i, j, k; - b32 hit; - - if (seek.size == 0){ - return str.size; - } - stop_at = str.size - seek.size + 1; - for (i = start; i < stop_at; ++i){ - if (str.str[i] == seek.str[0]){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - if (str.str[k] != seek.str[j]){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return(str.size); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -rfind_substr_s(String str, i32 start, String seek){ - i32 i, j, k; - b32 hit; - - if (seek.size == 0){ - return -1; - } - if (start + seek.size > str.size){ - start = str.size - seek.size; - } - for (i = start; i >= 0; --i){ - if (str.str[i] == seek.str[0]){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - if (str.str[k] != seek.str[j]){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return -1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -find_substr_insensitive_c(char *str, i32 start, String seek){ - i32 i, j, k; - b32 hit; - char a_upper, b_upper; - char first_test_char; - - if (seek.size == 0){ - return str_size(str); - } - first_test_char = char_to_upper(seek.str[0]); - for (i = start; str[i]; ++i){ - a_upper = char_to_upper(str[i]); - if (a_upper == first_test_char){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - a_upper = char_to_upper(str[k]); - b_upper = char_to_upper(seek.str[j]); - if (a_upper != b_upper){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return i; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -find_substr_insensitive_s(String str, i32 start, String seek){ - i32 i, j, k; - i32 stop_at; - b32 hit; - char a_upper, b_upper; - char first_test_char; - - if (seek.size == 0){ - return str.size; - } - stop_at = str.size - seek.size + 1; - first_test_char = char_to_upper(seek.str[0]); - for (i = start; i < stop_at; ++i){ - a_upper = char_to_upper(str.str[i]); - if (a_upper == first_test_char){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - a_upper = char_to_upper(str.str[k]); - b_upper = char_to_upper(seek.str[j]); - if (a_upper != b_upper){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return str.size; -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -has_substr_c(char *s, String seek){ - return (s[find_substr_c(s, 0, seek)] != 0); -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -has_substr_s(String s, String seek){ - return (find_substr_s(s, 0, seek) < s.size); -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -has_substr_insensitive_c(char *s, String seek){ - return (s[find_substr_insensitive_c(s, 0, seek)] != 0); -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -has_substr_insensitive_s(String s, String seek){ - return (find_substr_insensitive_s(s, 0, seek) < s.size); -} -#endif - -// -// String Copies and Appends -// - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -copy_fast_unsafe_cc(char *dest, char *src){ - char *start = dest; - while (*src != 0){ - *dest = *src; - ++dest; - ++src; - } - return (i32)(dest - start); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -copy_fast_unsafe_cs(char *dest, String src){ - i32 i = 0; - while (i != src.size){ - dest[i] = src.str[i]; - ++i; - } - return(src.size); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -copy_checked_ss(String *dest, String src){ - char *dest_str; - i32 i; - if (dest->memory_size < src.size){ - return 0; - } - dest_str = dest->str; - for (i = 0; i < src.size; ++i){ - dest_str[i] = src.str[i]; - } - dest->size = src.size; - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -copy_checked_cs(char *dest, i32 dest_cap, String src){ - i32 i; - if (dest_cap < src.size){ - return 0; - } - for (i = 0; i < src.size; ++i){ - dest[i] = src.str[i]; - } - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -copy_partial_sc(String *dest, char *src){ - i32 i = 0; - i32 memory_size = dest->memory_size; - char *dest_str = dest->str; - while (src[i] != 0){ - if (i >= memory_size){ - return 0; - } - dest_str[i] = src[i]; - ++i; - } - dest->size = i; - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -copy_partial_ss(String *dest, String src){ - char *dest_str = dest->str; - i32 memory_size = dest->memory_size; - b32 result = 0; - if (memory_size >= src.size){ - result = 1; - memory_size = src.size; - } - for (i32 i = 0; i < memory_size; ++i){ - dest_str[i] = src.str[i]; - } - dest->size = memory_size; - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -copy_partial_cs(char *dest, i32 dest_cap, String src){ - b32 result = 0; - i32 copy_size = dest_cap; - i32 i; - if (dest_cap >= src.size){ - result = 1; - copy_size = src.size; - } - for (i = 0; i < copy_size; ++i){ - dest[i] = src.str[i]; - } - return(result); -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE i32 -copy_cc(char *dest, char *src){ - return copy_fast_unsafe_cc(dest, src); -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE void -copy_ss(String *dest, String src){ - copy_checked_ss(dest, src); -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE void -copy_sc(String *dest, char *src){ - copy_partial_sc(dest, src); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -append_checked_ss(String *dest, String src){ - String end; - end = tailstr(*dest); - b32 result = copy_checked_ss(&end, src); - // NOTE(allen): This depends on end.size still being 0 if - // the check failed and no coppy occurred. - dest->size += end.size; - return result; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -append_partial_sc(String *dest, char *src){ - String end = tailstr(*dest); - b32 result = copy_partial_sc(&end, src); - dest->size += end.size; - return result; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -append_partial_ss(String *dest, String src){ - String end = tailstr(*dest); - b32 result = copy_partial_ss(&end, src); - dest->size += end.size; - return result; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -append_s_char(String *dest, char c){ - b32 result = 0; - if (dest->size < dest->memory_size){ - dest->str[dest->size++] = c; - result = 1; - } - return result; -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -append_ss(String *dest, String src){ - return append_partial_ss(dest, src); -} -#endif - - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE b32 -append_sc(String *dest, char *src){ - return append_partial_sc(dest, src); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -terminate_with_null(String *str){ - b32 result = 0; - if (str->size < str->memory_size){ - str->str[str->size] = 0; - result = 1; - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -append_padding(String *dest, char c, i32 target_size){ - b32 result = 1; - i32 offset = target_size - dest->size; - i32 r = 0; - if (offset > 0){ - for (r = 0; r < offset; ++r){ - if (append_s_char(dest, c) == 0){ - result = 0; - break; - } - } - } - return(result); -} -#endif - - -// -// Other Edits -// - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void -string_interpret_escapes(String src, char *dst) -{ - i32 mode = 0; - i32 j = 0; - for (i32 i = 0; i < src.size; ++i){ - switch (mode){ - case 0: - { - if (src.str[i] == '\\'){ - mode = 1; - } - else{ - dst[j++] = src.str[i]; - } - }break; - - case 1: - { - char c = src.str[i]; - switch (c){ - case '\\':{dst[j++] = '\\';} break; - case 'n': {dst[j++] = '\n';} break; - case 't': {dst[j++] = '\t';} break; - case '"': {dst[j++] = '"'; } break; - case '0': {dst[j++] = '\0';} break; - default: {dst[j++] = '\\'; dst[j++] = c;}break; - } - mode = 0; - }break; - } - } - dst[j] = 0; -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void -replace_char(String *str, char replace, char with){ - char *s = str->str; - i32 i = 0; - for (i = 0; i < str->size; ++i, ++s){ - if (*s == replace) *s = with; - } -} -#endif - -#if !defined(FSTRING_GUARD) -void -block_move(void *a_ptr, void *b_ptr, i32 s){ - u8 *a = (u8*)a_ptr; - u8 *b = (u8*)b_ptr; - if (a < b){ - for (i32 i = 0; i < s; ++i, ++a, ++b){ - *a = *b; - } - } - else if (a > b){ - a = a + s - 1; - b = b + s - 1; - for (i32 i = 0; i < s; ++i, --a, --b){ - *a = *b; - } - } -} - -void -replace_range_str(String *str, i32 first, i32 one_past_last, String with){ - i32 shift = with.size - (one_past_last - first); - i32 new_size = str->size + shift; - if (new_size <= str->memory_size){ - if (shift != 0){ - char *tail = str->str + one_past_last; - char *new_tail_pos = tail + shift; - block_move(new_tail_pos, tail, str->size - one_past_last); - } - block_move(str->str + first, with.str, with.size); - str->size += shift; - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void -replace_str_ss(String *str, String replace, String with){ - i32 i = 0; - for (;;){ - i = find_substr_s(*str, i, replace); - if (i >= str->size){ - break; - } - replace_range_str(str, i, i + replace.size, with); - i += with.size; - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void -replace_str_sc(String *str, String replace, char *with){ - String w = make_string_slowly(with); - replace_str_ss(str, replace, w); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void -replace_str_cs(String *str, char *replace, String with){ - String r = make_string_slowly(replace); - replace_str_ss(str, r, with); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void -replace_str_cc(String *str, char *replace, char *with){ - String r = make_string_slowly(replace); - String w = make_string_slowly(with); - replace_str_ss(str, r, w); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void -to_lower_cc(char *src, char *dst){ - for (; *src != 0; ++src){ - *dst++ = char_to_lower(*src); - } - *dst++ = 0; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void -to_lower_ss(String *dst, String src){ - i32 i = 0; - i32 size = src.size; - char *c = src.str; - char *d = dst->str; - - if (dst->memory_size >= size){ - for (; i < size; ++i){ - *d++ = char_to_lower(*c++); - } - dst->size = size; - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void -to_lower_s(String *str){ - i32 i = 0; - i32 size = str->size; - char *c = str->str; - for (; i < size; ++c, ++i){ - *c = char_to_lower(*c); - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void -to_upper_cc(char *src, char *dst){ - for (; *src != 0; ++src){ - *dst++ = char_to_upper(*src); - } - *dst++ = 0; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void -to_upper_ss(String *dst, String src){ - i32 i = 0; - i32 size = src.size; - char *c = src.str; - char *d = dst->str; - - if (dst->memory_size >= size){ - for (; i < size; ++i){ - *d++ = char_to_upper(*c++); - } - dst->size = size; - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void -to_upper_s(String *str){ - i32 i = 0; - i32 size = str->size; - char *c = str->str; - for (; i < size; ++c, ++i){ - *c = char_to_upper(*c); - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void -to_camel_cc(char *src, char *dst){ - char *c, ch; - i32 is_first = 1; - for (c = src; *c != 0; ++c){ - ch = *c; - if (char_is_alpha_numeric_true(ch)){ - if (is_first){ - is_first = 0; - ch = char_to_upper(ch); - } - else{ - ch = char_to_lower(ch); - } - } - else{ - is_first = 1; - } - *dst++ = ch; - } - *dst = 0; -} -#endif - - -// -// String <-> Number Conversions -// - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -int_to_str_size(i32 x){ - i32 size = 1; - if (x < 0){ - size = 2; - } - x /= 10; - while (x != 0){ - x /= 10; - ++size; - } - return(size); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -int_to_str(String *dest, i32 x){ - b32 result = 1; - char *str = dest->str; - i32 memory_size = dest->memory_size; - i32 size, i, j; - b32 negative; - - if (x == 0){ - str[0] = '0'; - dest->size = 1; - } - else{ - size = 0; - negative = 0; - if (x < 0){ - negative = 1; - x = -x; - str[size++] = '-'; - } - while (x != 0){ - if (size == memory_size){ - result = 0; - break; - } - i = x % 10; - x /= 10; - str[size++] = (char)('0' + i); - } - if (result){ - // NOTE(allen): Start i = 0 if not negative, start i = 1 if is negative because - should not be flipped if it is negative :) - for (i = negative, j = size-1; i < j; ++i, --j){ - char temp = str[i]; - str[i] = str[j]; - str[j] = temp; - } - dest->size = size; - } - else{ - dest->size = 0; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -append_int_to_str(String *dest, i32 x){ - String last_part = tailstr(*dest); - b32 result = int_to_str(&last_part, x); - if (result){ - dest->size += last_part.size; - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -u64_to_str_size(uint64_t x){ - i32 size = 1; - x /= 10; - while (x != 0){ - x /= 10; - ++size; - } - return(size); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -u64_to_str(String *dest, uint64_t x){ - b32 result = 1; - char *str = dest->str; - i32 memory_size = dest->memory_size; - i32 size, i, j; - - if (x == 0){ - str[0] = '0'; - dest->size = 1; - } - else{ - size = 0; - while (x != 0){ - if (size == memory_size){ - result = 0; - break; - } - i = x % 10; - x /= 10; - str[size++] = (char)('0' + i); - } - if (result){ - for (i = 0, j = size-1; i < j; ++i, --j){ - char temp = str[i]; - str[i] = str[j]; - str[j] = temp; - } - dest->size = size; - } - else{ - dest->size = 0; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -append_u64_to_str(String *dest, uint64_t x){ - String last_part = tailstr(*dest); - b32 result = u64_to_str(&last_part, x); - if (result){ - dest->size += last_part.size; - } - return(result); -} -#endif - -#if !defined(FSTRING_GUARD) -typedef struct Float_To_Str_Variables{ - b32 negative; - i32 int_part; - i32 dec_part; -} Float_To_Str_Variables; - -static Float_To_Str_Variables -get_float_vars(float x){ - Float_To_Str_Variables vars = {}; - - if (x < 0){ - vars.negative = 1; - x = -x; - } - - vars.int_part = (i32)(x); - vars.dec_part = (i32)((x - vars.int_part) * 1000); - - return(vars); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -float_to_str_size(float x){ - Float_To_Str_Variables vars = get_float_vars(x); - i32 size = vars.negative + int_to_str_size(vars.int_part) + 1 + int_to_str_size(vars.dec_part); - return(size); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -append_float_to_str(String *dest, float x){ - b32 result = 1; - Float_To_Str_Variables vars = get_float_vars(x); - - if (vars.negative){ - append_s_char(dest, '-'); - } - - append_int_to_str(dest, vars.int_part); - append_s_char(dest, '.'); - append_int_to_str(dest, vars.dec_part); - - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -float_to_str(String *dest, float x){ - b32 result = 1; - dest->size = 0; - append_float_to_str(dest, x); - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -str_is_int_c(char *str){ - b32 result = 1; - for (; *str; ++str){ - if (!char_is_numeric(*str)){ - result = 0; - break; - } - } - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -str_is_int_s(String str){ - b32 result = 1; - for (i32 i = 0; i < str.size; ++i){ - if (!char_is_numeric(str.str[i])){ - result = 0; - break; - } - } - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -str_to_int_c(char *str){ - i32 x = 0; - for (; *str; ++str){ - if (*str >= '0' && *str <= '9'){ - x *= 10; - x += *str - '0'; - } - else{ - x = 0; - break; - } - } - return(x); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -str_to_int_s(String str){ - i32 x, i; - if (str.size == 0){ - x = 0; - } - else{ - x = str.str[0] - '0'; - for (i = 1; i < str.size; ++i){ - x *= 10; - x += str.str[i] - '0'; - } - } - return(x); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -hexchar_to_int(char c){ - i32 x = 0; - if (c >= '0' && c <= '9'){ - x = c-'0'; - } - else if (c > 'F'){ - x = c+(10-'a'); - } - else{ - x = c+(10-'A'); - } - return(x); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK char -int_to_hexchar(i32 x){ - return (x<10)?((char)x+'0'):((char)x+'a'-10); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK u32 -hexstr_to_int(String str){ - u32 x; - i32 i; - if (str.size == 0){ - x = 0; - } - else{ - x = hexchar_to_int(str.str[0]); - for (i = 1; i < str.size; ++i){ - x *= 0x10; - x += hexchar_to_int(str.str[i]); - } - } - return(x); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -color_to_hexstr(String *s, u32 color){ - b32 result = 0; - i32 i; - - if (s->memory_size == 7 || s->memory_size == 8){ - result = 1; - s->size = 6; - s->str[6] = 0; - color = color & 0x00FFFFFF; - for (i = 5; i >= 0; --i){ - s->str[i] = int_to_hexchar(color & 0xF); - color >>= 4; - } - } - else if (s->memory_size > 8){ - result = 1; - s->size = 8; - s->str[8] = 0; - for (i = 7; i >= 0; --i){ - s->str[i] = int_to_hexchar(color & 0xF); - color >>= 4; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -hexstr_to_color(String s, u32 *out){ - b32 result = 0; - u32 color = 0; - if (s.size == 6){ - result = 1; - color = (u32)hexstr_to_int(s); - color |= (0xFF << 24); - *out = color; - } - else if (s.size == 8){ - result = 1; - color = (u32)hexstr_to_int(s); - *out = color; - } - return(result); -} -#endif - -// -// Directory String Management -// - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32 -reverse_seek_slash_pos(String str, i32 pos){ - i32 i = str.size - 1 - pos; - while (i >= 0 && !char_is_slash(str.str[i])){ - --i; - } - return i; -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE i32 -reverse_seek_slash(String str){ - return(reverse_seek_slash_pos(str, 0)); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE String -front_of_directory(String dir){ - return substr_tail(dir, reverse_seek_slash(dir) + 1); -} -#endif - -#if !defined(FSTRING_GUARD) -FSTRING_INLINE String -path_of_directory(String dir){ - return substr(dir, 0, reverse_seek_slash(dir) + 1); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -set_last_folder_sc(String *dir, char *folder_name, char slash){ - b32 result = 0; - i32 size = reverse_seek_slash(*dir) + 1; - dir->size = size; - if (append_sc(dir, folder_name)){ - if (append_s_char(dir, slash)){ - result = 1; - } - } - if (!result){ - dir->size = size; - } - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -set_last_folder_ss(String *dir, String folder_name, char slash){ - b32 result = 0; - i32 size = reverse_seek_slash(*dir) + 1; - dir->size = size; - if (append_ss(dir, folder_name)){ - if (append_s_char(dir, slash)){ - result = 1; - } - } - if (!result){ - dir->size = size; - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -file_extension(String str){ - i32 i; - for (i = str.size - 1; i >= 0; --i){ - if (str.str[i] == '.') break; - } - ++i; - return(make_string(str.str+i, str.size-i)); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -remove_extension(String *str){ - b32 result = 0; - i32 i; - for (i = str->size - 1; i >= 0; --i){ - if (str->str[i] == '.') break; - } - if (i >= 0){ - result = 1; - str->size = i + 1; - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -remove_last_folder(String *str){ - b32 result = 0; - i32 end = reverse_seek_slash_pos(*str, 1); - if (end >= 0){ - result = 1; - str->size = end + 1; - } - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -string_set_match_table(void *str_set, i32 item_size, i32 count, String str, i32 *match_index){ - b32 result = 0; - i32 i = 0; - uint8_t *ptr = (uint8_t*)str_set; - for (; i < count; ++i, ptr += item_size){ - if (match_ss(*(String*)ptr, str)){ - *match_index = i; - result = 1; - break; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32 -string_set_match(String *str_set, i32 count, String str, i32 *match_index){ - b32 result = string_set_match_table(str_set, sizeof(String), count, str, match_index); - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -get_first_double_line(String source){ - String line = {}; - i32 pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); - i32 pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n")); - if (pos1 < pos0){ - pos0 = pos1; - } - line = substr(source, 0, pos0); - return(line); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -get_next_double_line(String source, String line){ - String next = {}; - i32 pos = (i32)(line.str - source.str) + line.size; - i32 start = 0, pos0 = 0, pos1 = 0; - - if (pos < source.size){ - //Assert(source.str[pos] == '\n' || source.str[pos] == '\r'); - start = pos + 1; - - if (start < source.size){ - pos0 = find_substr_s(source, start, make_lit_string("\n\n")); - pos1 = find_substr_s(source, start, make_lit_string("\r\n\r\n")); - if (pos1 < pos0){ - pos0 = pos1; - } - next = substr(source, start, pos0 - start); - } - } - - return(next); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -get_next_word(String source, String prev_word){ - - String word = {}; - i32 pos0 = (i32)(prev_word.str - source.str) + prev_word.size; - i32 pos1 = 0; - char c = 0; - - for (; pos0 < source.size; ++pos0){ - c = source.str[pos0]; - if (!(char_is_whitespace(c) || c == '(' || c == ')')){ - break; - } - } - - if (pos0 < source.size){ - for (pos1 = pos0; pos1 < source.size; ++pos1){ - c = source.str[pos1]; - if (char_is_whitespace(c) || c == '(' || c == ')'){ - break; - } - } - - word = substr(source, pos0, pos1 - pos0); - } - - return(word); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -get_first_word(String source){ - String start_str = make_string(source.str, 0); - String word = get_next_word(source, start_str); - return(word); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -string_push(Cursor *cursor, i32 size){ - String result = {}; - if (size > 0){ - result.str = push_array(cursor, char, size); - if (result.str != 0){ - result.memory_size = size; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -string_push_copy(Cursor *cursor, String str){ - String result = {}; - if (str.str != 0){ - result.str = push_array(cursor, char, str.size + 1); - if (result.str != 0){ - result.memory_size = str.size + 1; - copy(&result, str); - result.str[result.size] = 0; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -string_push(Arena *arena, i32 size){ - String result = {}; - if (size > 0){ - result.str = push_array(arena, char, size); - if (result.str != 0){ - result.memory_size = size; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String -string_push_copy(Arena *arena, String str){ - String result = {}; - if (str.str != 0){ - result.str = push_array(arena, char, str.size + 1); - if (result.str != 0){ - result.memory_size = str.size + 1; - copy(&result, str); - result.str[result.size] = 0; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK char* -get_null_terminated(Arena *arena, String str){ - char *str_terminated = 0; - if (str.size < str.memory_size){ - if (str.str[str.size] != 0){ - str.str[str.size] = 0; - } - str_terminated = str.str; - } - else{ - str_terminated = push_array(arena, char, str.size + 1); - if (str_terminated != 0){ - String builder = make_string_cap(str_terminated, 0, str.size + 1); - append(&builder, str); - str_terminated[str.size] = 0; - } - } - return(str_terminated); -} -#endif - -// TODO(allen): eliminate this. -#ifndef FSTRING_EXPERIMENTAL -#define FSTRING_EXPERIMENTAL - -// NOTE(allen): experimental section, things below here are -// not promoted to public API level yet. - -typedef struct Absolutes{ - String a[8]; - i32 count; -} Absolutes; - -static void -get_absolutes(String name, Absolutes *absolutes, b32 implicit_first, b32 implicit_last){ - if (name.size != 0){ - i32 count = 0; - i32 max = (sizeof(absolutes->a)/sizeof(*absolutes->a)) - 1; - if (implicit_last) --max; - - String str; - str.str = name.str; - str.size = 0; - str.memory_size = 0; - b32 prev_was_wild = 0; - - if (implicit_first){ - absolutes->a[count++] = str; - prev_was_wild = 1; - } - - i32 i; - for (i = 0; i < name.size; ++i){ - if (name.str[i] == '*' && count < max){ - if (!prev_was_wild){ - str.memory_size = str.size; - absolutes->a[count++] = str; - str.size = 0; - } - str.str = name.str + i + 1; - prev_was_wild = 1; - } - else{ - ++str.size; - prev_was_wild = 0; - } - } - - str.memory_size = str.size; - absolutes->a[count++] = str; - - if (implicit_last){ - str.size = 0; - str.memory_size = 0; - absolutes->a[count++] = str; - } - - absolutes->count = count; - } - else{ - absolutes->count = 0; - } -} - -static b32 -wildcard_match_c(Absolutes *absolutes, char *x, i32 case_sensitive){ - b32 r = 1; - - if (absolutes->count > 0){ - String *a = absolutes->a; - - b32 (*match_func)(char*, String); - b32 (*match_part_func)(char*, String); - - if (case_sensitive){ - match_func = match_cs; - match_part_func = match_part_cs; - } - else{ - match_func = match_insensitive_cs; - match_part_func = match_part_insensitive_cs; - } - - if (absolutes->count == 1){ - r = match_func(x, *a); - } - else{ - if (!match_part_func(x, *a)){ - r = 0; - } - else{ - String *max = a + absolutes->count - 1; - x += a->size; - ++a; - while (a < max){ - if (*x == 0){ - r = 0; - break; - } - if (match_part_func(x, *a)){ - x += a->size; - ++a; - } - else{ - ++x; - } - } - if (r && a->size > 0){ - r = 0; - while (*x != 0){ - if (match_part_func(x, *a) && *(x + a->size) == 0){ - r = 1; - break; - } - else{ - ++x; - } - } - } - } - } - } - return(r); -} - -static b32 -wildcard_match_s(Absolutes *absolutes, String x, i32 case_sensitive){ - terminate_with_null(&x); - return(wildcard_match_c(absolutes, x.str, case_sensitive)); -} - -#endif - -#if defined(FSTRING_IMPLEMENTATION) -#undef FSTRING_IMPLEMENTATION -#define FSTRING_IMPL_GUARD -#endif - -#if !defined(FSTRING_GUARD) -#define FSTRING_GUARD -#endif - -#endif - -// BOTTOM - diff --git a/4coder_log_parser.cpp b/4coder_log_parser.cpp index 360a1824..0917f738 100644 --- a/4coder_log_parser.cpp +++ b/4coder_log_parser.cpp @@ -907,8 +907,6 @@ CUSTOM_COMMAND_SIG(log_graph__escape) CUSTOM_DOC("Ends the log grapher") { if (log_view != 0){ - Managed_Scope scope = view_get_managed_scope(app, log_view); - managed_variable_set(app, scope, view_render_hook, 0); view_end_ui_mode(app, log_view); log_view = 0; } @@ -1044,8 +1042,8 @@ CUSTOM_DOC("Parser *log* and displays the 'log graph' UI") log_view = get_active_view(app, AccessAll); } Managed_Scope scope = view_get_managed_scope(app, log_view); - u64 render_hook_value = (u64)PtrAsInt(log_graph_render); - managed_variable_set(app, scope, view_render_hook, render_hook_value); + View_Render_Hook **hook = scope_attachment(app, scope, view_render_hook, View_Render_Hook*); + *hook = log_graph_render; view_set_setting(app, log_view, ViewSetting_UICommandMap, default_log_graph_map); view_begin_ui_mode(app, log_view); view_set_quit_ui_handler(app, log_view, ui_quit_clear_render_hook); diff --git a/4coder_metadata_generator.cpp b/4coder_metadata_generator.cpp index 28e81810..6527d36f 100644 --- a/4coder_metadata_generator.cpp +++ b/4coder_metadata_generator.cpp @@ -8,8 +8,6 @@ #include "4coder_base_types.h" -#include "4coder_lib/4coder_string.h" - #include "4coder_base_types.cpp" #include "4coder_stringf.cpp" #include "4coder_malloc_allocator.cpp" @@ -77,13 +75,13 @@ struct Reader{ Arena *error_arena; char *source_name; String_Const_char text; - Cpp_Token_Array tokens; - Cpp_Token *ptr; + Token_Array tokens; + Token *ptr; }; struct Temp_Read{ Reader *reader; - Cpp_Token *pos; + Token *pos; }; static Reader @@ -96,9 +94,9 @@ make_reader(Cpp_Token_Array array, char *source_name, String_Const_char text){ return(reader); } -static Cpp_Token +static Token prev_token(Reader *reader){ - Cpp_Token result = {}; + Token result = {}; for (;;){ if (reader->ptr > reader->tokens.tokens + reader->tokens.count){ @@ -123,9 +121,9 @@ prev_token(Reader *reader){ return(result); } -static Cpp_Token +static Token get_token(Reader *reader){ - Cpp_Token result = {}; + Token result = {}; for (;;){ if (reader->ptr < reader->tokens.tokens){ @@ -151,9 +149,9 @@ get_token(Reader *reader){ return(result); } -static Cpp_Token +static Token peek_token(Reader *reader){ - Cpp_Token result = {}; + Token result = {}; if (reader->ptr < reader->tokens.tokens){ reader->ptr = reader->tokens.tokens; @@ -171,7 +169,7 @@ peek_token(Reader *reader){ static int32_t peek_pos(Reader *reader){ - Cpp_Token token = peek_token(reader); + Token token = peek_token(reader); return(token.start); } @@ -202,7 +200,7 @@ end_temp_read(Temp_Read temp){ /////////////////////////////// static String_Const_char -token_str(String_Const_char text, Cpp_Token token){ +token_str(String_Const_char text, Token token){ String_Const_char str = string_prefix(string_skip(text, token.start), token.size); return(str); } @@ -306,7 +304,7 @@ require_key_identifier(Reader *reader, char *str, int32_t *opt_pos_out = 0){ String_Const_char string = SCchar(str); - Cpp_Token token = get_token(reader); + Token token = get_token(reader); if (token.type == CPP_TOKEN_IDENTIFIER){ String_Const_char lexeme = token_str(reader->text, token); if (string_match(lexeme, string)){ @@ -331,7 +329,7 @@ static b32 require_open_parenthese(Reader *reader, int32_t *opt_pos_out = 0){ b32 success = false; - Cpp_Token token = get_token(reader); + Token token = get_token(reader); if (token.type == CPP_TOKEN_PARENTHESE_OPEN){ success = true; if (opt_pos_out != 0){ @@ -350,7 +348,7 @@ static b32 require_close_parenthese(Reader *reader, int32_t *opt_pos_out = 0){ b32 success = false; - Cpp_Token token = get_token(reader); + Token token = get_token(reader); if (token.type == CPP_TOKEN_PARENTHESE_CLOSE){ success = true; if (opt_pos_out != 0){ @@ -369,7 +367,7 @@ static b32 require_comma(Reader *reader, int32_t *opt_pos_out = 0){ b32 success = false; - Cpp_Token token = get_token(reader); + Token token = get_token(reader); if (token.type == CPP_TOKEN_COMMA){ success = true; if (opt_pos_out != 0){ @@ -388,7 +386,7 @@ static b32 require_define(Reader *reader, int32_t *opt_pos_out = 0){ b32 success = false; - Cpp_Token token = get_token(reader); + Token token = get_token(reader); if (token.type == CPP_PP_DEFINE){ success = true; if (opt_pos_out != 0){ @@ -407,7 +405,7 @@ static b32 extract_identifier(Reader *reader, String_Const_char *str_out, int32_t *opt_pos_out = 0){ b32 success = false; - Cpp_Token token = get_token(reader); + Token token = get_token(reader); if (token.type == CPP_TOKEN_IDENTIFIER){ String_Const_char lexeme = token_str(reader->text, token); *str_out = lexeme; @@ -428,7 +426,7 @@ static b32 extract_integer(Reader *reader, String_Const_char *str_out, int32_t *opt_pos_out = 0){ b32 success = false; - Cpp_Token token = get_token(reader); + Token token = get_token(reader); if (token.type == CPP_TOKEN_INTEGER_CONSTANT){ String_Const_char lexeme = token_str(reader->text, token); *str_out = lexeme; @@ -449,7 +447,7 @@ static b32 extract_string(Reader *reader, String_Const_char *str_out, int32_t *opt_pos_out = 0){ b32 success = false; - Cpp_Token token = get_token(reader); + Token token = get_token(reader); if (token.type == CPP_TOKEN_STRING_CONSTANT){ String_Const_char lexeme = token_str(reader->text, token); *str_out = lexeme; @@ -598,14 +596,14 @@ parse_alias(Arena *arena, Meta_Command_Entry_Arrays *arrays, Reader *reader){ static void parse_text(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, char *source_name, String_Const_char text){ - Cpp_Token_Array array = cpp_make_token_array(1024); + Token_Array array = cpp_make_token_array(1024); cpp_lex_file(text.str, (i32)text.size, &array); Reader reader_ = make_reader(array, source_name, text); Reader *reader = &reader_; for (;;){ - Cpp_Token token = get_token(reader); + Token token = get_token(reader); if (token.type == CPP_TOKEN_IDENTIFIER){ String_Const_char lexeme = token_str(text, token); @@ -617,7 +615,7 @@ parse_text(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, char *source_n b32 found_start_pos = false; for (int32_t R = 0; R < 10; ++R){ - Cpp_Token p_token = prev_token(reader); + Token p_token = prev_token(reader); if (p_token.type == CPP_TOKEN_IDENTIFIER){ String_Const_char p_lexeme = token_str(text, p_token); if (string_match(p_lexeme, string_litexpr("CUSTOM_COMMAND_SIG"))){ @@ -644,7 +642,7 @@ parse_text(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, char *source_n b32 found_start_pos = false; for (int32_t R = 0; R < 3; ++R){ - Cpp_Token p_token = prev_token(reader); + Token p_token = prev_token(reader); if (p_token.type == CPP_PP_DEFINE){ if (R == 2){ found_start_pos = true; diff --git a/4coder_scope_commands.cpp b/4coder_scope_commands.cpp index 54f5f7be..d04749d0 100644 --- a/4coder_scope_commands.cpp +++ b/4coder_scope_commands.cpp @@ -4,12 +4,12 @@ // TOP -static b32 parse_statement_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *token_out); +static b32 parse_statement_down(Application_Links *app, Statement_Parser *parser, Token *token_out); //////////////////////////////// static Find_Scope_Token_Type -find_scope_get_token_type(u32 flags, Cpp_Token_Type token_type){ +find_scope_get_token_type(u32 flags, Token_Type token_type){ Find_Scope_Token_Type type = FindScopeTokenType_None; if (flags & FindScope_Brace){ switch (token_type){ @@ -40,8 +40,10 @@ find_scope_get_token_type(u32 flags, Cpp_Token_Type token_type){ static b32 find_scope_top(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 flags, i64 *end_pos_out){ - Cpp_Get_Token_Result get_result = {}; b32 success = false; + NotImplemented; +#if 0 + Cpp_Get_Token_Result get_result = {}; i32 position = 0; if (get_token_from_pos(app, buffer, start_pos, &get_result)){ i32 token_index = get_result.token_index; @@ -56,7 +58,7 @@ find_scope_top(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 flag if (token_range.first != 0){ Token_Iterator token_it = make_token_iterator(token_range, token_index); i32 nest_level = 0; - for (Cpp_Token *token = token_iterator_current(&token_it); + for (Token *token = token_iterator_current(&token_it); token != 0; token = token_iterator_goto_prev(&token_it)){ Find_Scope_Token_Type type = find_scope_get_token_type(flags, token->type); @@ -86,13 +88,15 @@ find_scope_top(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 flag } finished:; *end_pos_out = position; +#endif return(success); } static b32 find_scope_bottom(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 flags, i64 *end_pos_out){ - Cpp_Get_Token_Result get_result = {}; b32 success = false; +#if 0 + Cpp_Get_Token_Result get_result = {}; i32 position = 0; if (get_token_from_pos(app, buffer, start_pos, &get_result)){ i32 token_index = get_result.token_index + 1; @@ -107,7 +111,7 @@ find_scope_bottom(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 f if (token_range.first != 0){ Token_Iterator token_it = make_token_iterator(token_range, token_index); i32 nest_level = 0; - for (Cpp_Token *token = token_iterator_current(&token_it); + for (Token *token = token_iterator_current(&token_it); token != 0; token = token_iterator_goto_next(&token_it)){ Find_Scope_Token_Type type = find_scope_get_token_type(flags, token->type); @@ -137,13 +141,16 @@ find_scope_bottom(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 f } finished:; *end_pos_out = position; +#endif return(success); } static b32 find_next_scope(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 flags, i64 *end_pos_out){ + b32 success = false; + NotImplemented; +#if 0 Cpp_Get_Token_Result get_result = {}; - b32 success = 0; i64 position = 0; if (get_token_from_pos(app, buffer, start_pos, &get_result)){ i32 token_index = get_result.token_index + 1; @@ -153,7 +160,7 @@ find_next_scope(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 fla Token_Iterator token_it = make_token_iterator(token_range, token_index); if (HasFlag(flags, FindScope_NextSibling)){ i32 nest_level = 1; - for (Cpp_Token *token = token_iterator_current(&token_it); + for (Token *token = token_iterator_current(&token_it); token != 0; token = token_iterator_goto_next(&token_it)){ Find_Scope_Token_Type type = find_scope_get_token_type(flags, token->type); @@ -184,7 +191,7 @@ find_next_scope(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 fla } } else{ - for (Cpp_Token *token = token_iterator_current(&token_it); + for (Token *token = token_iterator_current(&token_it); token != 0; token = token_iterator_goto_next(&token_it)){ Find_Scope_Token_Type type = find_scope_get_token_type(flags, token->type); @@ -203,13 +210,16 @@ find_next_scope(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 fla } finished:; *end_pos_out = position; +#endif return(success); } static b32 find_prev_scope(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 flags, i64 *end_pos_out){ - Cpp_Get_Token_Result get_result = {}; b32 success = false; + NotImplemented; +#if 0 + Cpp_Get_Token_Result get_result = {}; i64 position = 0; if (get_token_from_pos(app, buffer, start_pos, &get_result)){ i32 token_index = get_result.token_index - 1; @@ -219,7 +229,7 @@ find_prev_scope(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 fla Token_Iterator token_it = make_token_iterator(token_range, token_index); if (flags & FindScope_NextSibling){ i32 nest_level = -1; - for (Cpp_Token *token = token_iterator_current(&token_it); + for (Token *token = token_iterator_current(&token_it); token != 0; token = token_iterator_goto_prev(&token_it)){ Find_Scope_Token_Type type = find_scope_get_token_type(flags, token->type); @@ -250,7 +260,7 @@ find_prev_scope(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 fla } } else{ - for (Cpp_Token *token = token_iterator_current(&token_it); + for (Token *token = token_iterator_current(&token_it); token != 0; token = token_iterator_goto_prev(&token_it)){ Find_Scope_Token_Type type = find_scope_get_token_type(flags, token->type); @@ -269,6 +279,7 @@ find_prev_scope(Application_Links *app, Buffer_ID buffer, i64 start_pos, u32 fla } finished:; *end_pos_out = position; +#endif return(success); } @@ -483,15 +494,17 @@ CUSTOM_DOC("Deletes the braces surrounding the currently selected scope. Leaves } } -static Cpp_Token* +static Token* parser_next_token(Statement_Parser *parser){ - return(token_iterator_goto_next(&parser->token_iterator)); + return(token_iter_next(&parser->token_iterator)); } static b32 -parse_for_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *token_out){ +parse_for_down(Application_Links *app, Statement_Parser *parser, Token *token_out){ b32 success = false; - Cpp_Token *token = parser_next_token(parser); + NotImplemented; +#if 0 + Token *token = parser_next_token(parser); i32 paren_level = 0; for (;token != 0;){ @@ -520,13 +533,16 @@ parse_for_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *toke } finished:; +#endif return(success); } static b32 -parse_if_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *token_out){ +parse_if_down(Application_Links *app, Statement_Parser *parser, Token *token_out){ b32 success = false; - Cpp_Token *token = parser_next_token(parser); + NotImplemented; +#if 0 + Token *token = parser_next_token(parser); if (token != 0){ success = parse_statement_down(app, parser, token_out); if (success){ @@ -536,13 +552,16 @@ parse_if_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *token } } } +#endif return(success); } static b32 -parse_block_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *token_out){ +parse_block_down(Application_Links *app, Statement_Parser *parser, Token *token_out){ b32 success = false; - Cpp_Token *token = parser_next_token(parser); + NotImplemented; +#if 0 + Token *token = parser_next_token(parser); i32 nest_level = 0; while (token != 0){ @@ -566,13 +585,16 @@ parse_block_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *to } finished:; +#endif return(success); } static b32 -parse_statement_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *token_out){ +parse_statement_down(Application_Links *app, Statement_Parser *parser, Token *token_out){ b32 success = false; - Cpp_Token *token = parser_next_token(parser); + NotImplemented; +#if 0 + Token *token = parser_next_token(parser); if (token != 0){ b32 not_getting_block = false; @@ -628,17 +650,21 @@ parse_statement_down(Application_Links *app, Statement_Parser *parser, Cpp_Token } finished:; +#endif return(success); } static Statement_Parser make_statement_parser(Application_Links *app, Buffer_ID buffer, i32 token_index){ Statement_Parser parser = {}; + NotImplemented; +#if 0 Token_Range token_range = buffer_get_token_range(app, buffer); if (token_range.first != 0){ parser.token_iterator = make_token_iterator(token_range, token_index); parser.buffer = buffer; } +#endif return(parser); } @@ -656,7 +682,7 @@ find_whole_statement_down(Application_Links *app, Buffer_ID buffer, i64 pos, i64 parser_next_token(&parser); } - Cpp_Token end_token = {}; + Token end_token = {}; if (parse_statement_down(app, &parser, &end_token)){ end = end_token.start + end_token.size; result = true; diff --git a/4coder_search.cpp b/4coder_search.cpp index 4071213d..009bf7db 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -382,12 +382,11 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with Managed_Scope scope = view_get_managed_scope(app, view); b32 first_completion = false; - u64 rewrite = 0; - managed_variable_get(app, scope, view_rewrite_loc, &rewrite); - if (rewrite != RewriteWordComplete){ + Rewrite_Type *rewrite = scope_attachment(app, scope, view_rewrite_loc, Rewrite_Type); + if (*rewrite != Rewrite_WordComplete){ first_completion = true; } - managed_variable_set(app, scope, view_next_rewrite_loc, RewriteWordComplete); + *rewrite = Rewrite_WordComplete; local_persist Arena completion_arena = {}; if (completion_arena.base_allocator == 0){ diff --git a/4coder_table.cpp b/4coder_table.cpp index 8e18c842..400da2a9 100644 --- a/4coder_table.cpp +++ b/4coder_table.cpp @@ -171,7 +171,7 @@ table_erase(Table_u64_u64 *table, u64 key){ return(table_erase(table, lookup)); } -internal b32 +internal void table_clear(Table_u64_u64 *table){ block_zero_dynamic_array(table->keys, table->slot_count); block_zero_dynamic_array(table->vals, table->slot_count); @@ -324,7 +324,7 @@ table_erase(Table_u32_u16 *table, u32 key){ return(table_erase(table, lookup)); } -internal b32 +internal void table_clear(Table_u32_u16 *table){ block_zero_dynamic_array(table->keys, table->slot_count); block_zero_dynamic_array(table->vals, table->slot_count); @@ -480,7 +480,7 @@ table_erase(Table_Data_u64 *table, Data key){ return(result); } -internal b32 +internal void table_clear(Table_Data_u64 *table){ block_zero_dynamic_array(table->keys, table->slot_count); block_zero_dynamic_array(table->vals, table->slot_count); @@ -634,7 +634,7 @@ table_erase(Table_u64_Data *table, u64 key){ return(result); } -internal b32 +internal void table_clear(Table_u64_Data *table){ block_zero_dynamic_array(table->keys, table->slot_count); block_zero_dynamic_array(table->vals, table->slot_count); @@ -785,7 +785,7 @@ table_erase(Table_Data_Data *table, Data key){ return(result); } -internal b32 +internal void table_clear(Table_Data_Data *table){ block_zero_dynamic_array(table->keys, table->slot_count); block_zero_dynamic_array(table->vals, table->slot_count); diff --git a/4coder_ui_helper.cpp b/4coder_ui_helper.cpp index 418b85f0..960fa11f 100644 --- a/4coder_ui_helper.cpp +++ b/4coder_ui_helper.cpp @@ -4,10 +4,6 @@ // TOP -// TODO(allen): documentation comment here - -//////////////////////////////// - typedef u32 View_Get_UI_Flags; enum{ ViewGetUIFlag_KeepDataAsIs = 0, @@ -19,36 +15,36 @@ view_get_ui_data(Application_Links *app, View_ID view_id, View_Get_UI_Flags flag b32 result = false; Managed_Scope scope = view_get_managed_scope(app, view_id); if (scope != 0){ - Managed_Object ui_data_object = 0; - if (managed_variable_get(app, scope, view_ui_data, &ui_data_object)){ - if (ui_data_object == 0){ - Managed_Object new_ui_data_object = alloc_managed_memory_in_scope(app, scope, sizeof(UI_Storage), 1); - Managed_Object arena_object = alloc_managed_arena_in_scope(app, scope, (8 << 10)); - Arena *arena = 0; - if (managed_object_load_data(app, arena_object, 0, 1, &arena)){ - UI_Data *ui_data = push_array(arena, UI_Data, 1); - UI_Storage storage = {}; - storage.data = ui_data; - storage.arena = arena; - storage.arena_object = arena_object; - storage.temp = begin_temp(arena); - if (managed_object_store_data(app, new_ui_data_object, 0, 1, &storage)){ - if (managed_variable_set(app, scope, view_ui_data, new_ui_data_object)){ - ui_data_object = new_ui_data_object; - } - } - } + Managed_Object *ui_data_object_ptr = scope_attachment(app, scope, view_ui_data, Managed_Object); + Managed_Object ui_data_object = *ui_data_object_ptr; + if (ui_data_object == 0){ + Managed_Object new_ui_data_object = alloc_managed_memory_in_scope(app, scope, sizeof(UI_Storage), 1); + + Base_Allocator *allocator = managed_scope_allocator(app, scope); + Arena arena_temp = make_arena(allocator, KB(8)); + Arena *arena = push_array(&arena_temp, Arena, 1); + block_copy_struct(arena, &arena_temp); + + UI_Data *ui_data = push_array(arena, UI_Data, 1); + UI_Storage storage = {}; + storage.data = ui_data; + storage.arena = arena; + storage.temp = begin_temp(arena); + if (managed_object_store_data(app, new_ui_data_object, 0, 1, &storage)){ + *ui_data_object_ptr = new_ui_data_object; + ui_data_object = new_ui_data_object; } - if (ui_data_object != 0){ - UI_Storage storage = {}; - if (managed_object_load_data(app, ui_data_object, 0, 1, &storage)){ - *ui_data_out = storage.data; - *ui_arena_out = storage.arena; - if ((flags & ViewGetUIFlag_ClearData) != 0){ - end_temp(storage.temp); - } - result = true; + + } + if (ui_data_object != 0){ + UI_Storage storage = {}; + if (managed_object_load_data(app, ui_data_object, 0, 1, &storage)){ + *ui_data_out = storage.data; + *ui_arena_out = storage.arena; + if ((flags & ViewGetUIFlag_ClearData) != 0){ + end_temp(storage.temp); } + result = true; } } } @@ -60,16 +56,16 @@ view_clear_ui_data(Application_Links *app, View_ID view_id){ b32 result = false; Managed_Scope scope = view_get_managed_scope(app, view_id); if (scope != 0){ - Managed_Object ui_data_object = 0; - if (managed_variable_get(app, scope, view_ui_data, &ui_data_object)){ - if (ui_data_object != 0){ - UI_Storage storage = {}; - if (managed_object_load_data(app, ui_data_object, 0, 1, &storage)){ - managed_object_free(app, storage.arena_object); - managed_object_free(app, ui_data_object); - managed_variable_set(app, scope, view_ui_data, 0); - result = true; - } + Managed_Object *ui_data_object_ptr = scope_attachment(app, scope, view_ui_data, Managed_Object); + Managed_Object ui_data_object = *ui_data_object_ptr; + if (ui_data_object != 0){ + UI_Storage storage = {}; + if (managed_object_load_data(app, ui_data_object, 0, 1, &storage)){ + Arena arena_temp = *storage.arena; + linalloc_clear(&arena_temp); + managed_object_free(app, ui_data_object); + *ui_data_object_ptr = 0; + result = true; } } } diff --git a/4coder_ui_helper.h b/4coder_ui_helper.h index ec979b1b..e93da4d3 100644 --- a/4coder_ui_helper.h +++ b/4coder_ui_helper.h @@ -47,7 +47,6 @@ struct UI_Data{ struct UI_Storage{ UI_Data *data; Arena *arena; - Managed_Object arena_object; Temp_Memory temp; }; diff --git a/4ed.cpp b/4ed.cpp index ddd28283..50198168 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -361,22 +361,22 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){ switch (hook_id){ case special_hook_open_file: { - models->hook_open_file = (Open_File_Hook_Function*)unit->hook.func; + models->hook_open_file = (Buffer_Hook_Function*)unit->hook.func; }break; case special_hook_new_file: { - models->hook_new_file = (Open_File_Hook_Function*)unit->hook.func; + models->hook_new_file = (Buffer_Hook_Function*)unit->hook.func; }break; case special_hook_save_file: { - models->hook_save_file = (Open_File_Hook_Function*)unit->hook.func; + models->hook_save_file = (Buffer_Hook_Function*)unit->hook.func; }break; case special_hook_end_file: { - models->hook_end_file = (Open_File_Hook_Function*)unit->hook.func; + models->hook_end_file = (Buffer_Hook_Function*)unit->hook.func; }break; case special_hook_file_edit_range: @@ -735,8 +735,7 @@ app_setup_memory(System_Functions *system, Application_Memory *memory){ Models *models = push_array_zero(&cursor, Models, 1); models->mem.arena = make_arena_system(system); models->base_allocator = models->mem.arena.base_allocator; - heap_init(&models->mem.heap); - heap_extend(&models->mem.heap, memory->target_memory, memory->target_memory_size); + heap_init(&models->mem.heap, models->base_allocator); return(models); } @@ -877,13 +876,6 @@ App_Init_Sig(app_init){ } } - { - umem memsize = KB(8); - void *mem = push_array(arena, u8, (i32)memsize); - parse_context_init_memory(&models->parse_context_memory, mem, memsize); - parse_context_add_default(&models->parse_context_memory, &models->mem.heap); - } - { Assert(models->config_api.get_bindings != 0); i32 wanted_size = models->config_api.get_bindings(models->app_links.memory, models->app_links.memory_size); @@ -892,8 +884,9 @@ App_Init_Sig(app_init){ memset(models->app_links.memory, 0, wanted_size); } - dynamic_variables_init(&models->variable_layout); - dynamic_workspace_init(&models->mem.heap, &models->lifetime_allocator, DynamicWorkspace_Global, 0, &models->dynamic_workspace); + managed_ids_init(models->base_allocator, &models->managed_id_set); + lifetime_allocator_init(models->base_allocator, &models->lifetime_allocator); + dynamic_workspace_init(&models->lifetime_allocator, DynamicWorkspace_Global, 0, &models->dynamic_workspace); // NOTE(allen): file setup working_set_init(models, &models->working_set); @@ -946,7 +939,7 @@ App_Init_Sig(app_init){ Heap *heap = &models->mem.heap; for (i32 i = 0; i < ArrayCount(init_files); ++i){ Editing_File *file = working_set_allocate_file(&models->working_set, &models->lifetime_allocator); - buffer_bind_name(models, heap, arena, &models->working_set, file, init_files[i].name); + buffer_bind_name(models, arena, &models->working_set, file, init_files[i].name); if (init_files[i].ptr != 0){ *init_files[i].ptr = file; @@ -956,7 +949,7 @@ App_Init_Sig(app_init){ file_create_from_string(models, file, SCu8(), attributes); if (init_files[i].read_only){ file->settings.read_only = true; - history_free(&models->mem.heap, &file->state.history); + history_free(&file->state.history); } file->settings.never_kill = true; @@ -966,13 +959,13 @@ App_Init_Sig(app_init){ // NOTE(allen): setup first panel { Panel *panel = layout_initialize(arena, &models->layout); - View *new_view = live_set_alloc_view(&models->mem.heap, &models->lifetime_allocator, &models->live_set, panel); + View *new_view = live_set_alloc_view(&models->lifetime_allocator, &models->live_set, panel); view_set_file(system, models, new_view, models->scratch_buffer); } // NOTE(allen): miscellaneous init hot_directory_init(system, arena, &models->hot_directory, current_directory); - child_process_container_init(&models->child_processes, models); + child_process_container_init(models->base_allocator, &models->child_processes); models->user_up_key = key_up; models->user_down_key = key_down; models->period_wakeup_timer = system->wake_up_timer_create(); diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 7b5886d5..fc95fab9 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -28,11 +28,6 @@ api_check_buffer(Editing_File *file){ return(file != 0); } -internal b32 -api_check_buffer_and_tokens(Editing_File *file){ - return(api_check_buffer(file) && file->state.token_array.tokens != 0); -} - internal b32 api_check_buffer(Editing_File *file, Access_Flag access){ return(api_check_buffer(file) && access_test(file_get_access_flags(file), access)); @@ -173,14 +168,6 @@ Push_Clipboard_Index(Application_Links *app, Arena *arena, i32 clipboard_id, i32 return(result); } -API_EXPORT Parse_Context_ID -Create_Parse_Context(Application_Links *app, Parser_String_And_Type *kw, u32 kw_count, Parser_String_And_Type *pp, u32 pp_count) -{ - Models *models = (Models*)app->cmd_context; - Parse_Context_ID id = parse_context_add(&models->parse_context_memory, &models->mem.heap, kw, kw_count, pp, pp_count); - return(id); -} - API_EXPORT i32 Get_Buffer_Count(Application_Links *app) { @@ -645,17 +632,6 @@ Buffer_Set_Dirty_State(Application_Links *app, Buffer_ID buffer_id, Dirty_State return(result); } -API_EXPORT b32 -Buffer_Tokens_Are_Ready(Application_Links *app, Buffer_ID buffer_id){ - Models *models = (Models*)app->cmd_context; - Editing_File *file = imp_get_file(models, buffer_id); - b32 result = false; - if (api_check_buffer(file)){ - result = file_tokens_are_ready(file); - } - return(result); -} - API_EXPORT b32 Buffer_Get_Setting(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_ID setting, i32 *value_out) { @@ -665,36 +641,6 @@ Buffer_Get_Setting(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_I if (api_check_buffer(file)){ result = true; switch (setting){ - case BufferSetting_Lex: - { - *value_out = file->settings.tokens_exist; - }break; - - case BufferSetting_LexWithoutStrings: - { - *value_out = file->settings.tokens_without_strings; - }break; - - case BufferSetting_ParserContext: - { - *value_out = file->settings.parse_context_id; - }break; - - case BufferSetting_WrapLine: - { - //*value_out = !file->settings.unwrapped_lines; - }break; - - case BufferSetting_WrapPosition: - { - //*value_out = file->settings.display_width; - }break; - - case BufferSetting_MinimumBaseWrapPosition: - { - //*value_out = file->settings.minimum_base_display_width; - }break; - case BufferSetting_MapID: { *value_out = file->settings.base_map_id; @@ -715,13 +661,6 @@ Buffer_Get_Setting(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_I *value_out = file->settings.read_only; }break; - case BufferSetting_VirtualWhitespace: - { -#if 0 - *value_out = file->settings.virtual_white; -#endif - }break; - case BufferSetting_RecordsHistory: { *value_out = history_is_activated(&file->state.history); @@ -746,94 +685,6 @@ Buffer_Set_Setting(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_I if (api_check_buffer(file)){ result = true; switch (setting){ - case BufferSetting_Lex: - { - if (file->settings.tokens_exist){ - if (!value){ - file_kill_tokens(system, &models->mem.heap, file); - } - } - else{ - if (value){ - file_first_lex(system, models, file); - } - } - }break; - - case BufferSetting_LexWithoutStrings: - { - if (file->settings.tokens_exist){ - if ((b8)value != file->settings.tokens_without_strings){ - file_kill_tokens(system, &models->mem.heap, file); - file->settings.tokens_without_strings = (b8)value; - file_first_lex(system, models, file); - } - } - else{ - file->settings.tokens_without_strings = (b8)value; - } - }break; - - case BufferSetting_ParserContext: - { - u32 fixed_value = parse_context_valid_id(&models->parse_context_memory, (u32)value); - - if (file->settings.tokens_exist){ - if (fixed_value != file->settings.parse_context_id){ - file_kill_tokens(system, &models->mem.heap, file); - file->settings.parse_context_id = fixed_value; - file_first_lex(system, models, file); - } - } - else{ - file->settings.parse_context_id = fixed_value; - } - }break; - - case BufferSetting_WrapLine: - { - //file->settings.unwrapped_lines = !value; - }break; - - case BufferSetting_WrapPosition: - { -#if 0 - i32 new_value = value; - if (new_value < 48){ - new_value = 48; - } - if (new_value != file->settings.display_width){ - Face *face = font_set_face_from_id(&models->font_set, file->settings.font_id); - file->settings.display_width = new_value; - file_measure_wraps(system, &models->mem, file, face); - adjust_views_looking_at_file_to_new_cursor(system, models, file); - } -#endif - }break; - - case BufferSetting_MinimumBaseWrapPosition: - { -#if 0 - i32 new_value = value; - if (new_value < 0){ - new_value = 0; - } - if (new_value != file->settings.minimum_base_display_width){ - Face *face = font_set_face_from_id(&models->font_set, file->settings.font_id); - file->settings.minimum_base_display_width = new_value; - file_measure_wraps(system, &models->mem, file, face); - adjust_views_looking_at_file_to_new_cursor(system, models, file); - } -#endif - }break; - - case BufferSetting_WrapIndicator: - { -#if 0 - file->settings.wrap_indicator = value; -#endif - }break; - case BufferSetting_MapID: { if (value < mapid_global){ @@ -914,7 +765,7 @@ Buffer_Set_Setting(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_I } else{ if (history_is_activated(&file->state.history)){ - history_free(&models->mem.heap, &file->state.history); + history_free(&file->state.history); } } }break; @@ -941,18 +792,6 @@ Buffer_Get_Managed_Scope(Application_Links *app, Buffer_ID buffer_id) return(result); } -API_EXPORT Cpp_Token_Array -Buffer_Get_Token_Array(Application_Links *app, Buffer_ID buffer_id) -{ - Models *models = (Models*)app->cmd_context; - Editing_File *file = imp_get_file(models, buffer_id); - Cpp_Token_Array result = {}; - if (api_check_buffer_and_tokens(file)){ - result = file->state.token_array; - } - return(result); -} - API_EXPORT b32 Buffer_Send_End_Signal(Application_Links *app, Buffer_ID buffer_id) { @@ -1027,7 +866,7 @@ Buffer_Kill(Application_Links *app, Buffer_ID buffer_id, Buffer_Kill_Flag flags) if (file->canon.name_size != 0){ buffer_unbind_file(system, working_set, file); } - file_free(system, &models->mem.heap, &models->lifetime_allocator, working_set, file); + file_free(system, &models->lifetime_allocator, working_set, file); working_set_free_file(&models->mem.heap, working_set, file); Layout *layout = &models->layout; @@ -1109,7 +948,7 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl } Working_Set *working_set = &models->working_set; - file_free(system, &models->mem.heap, &models->lifetime_allocator, working_set, file); + file_free(system, &models->lifetime_allocator, working_set, file); working_set_file_default_settings(working_set, file); file_create_from_string(models, file, SCu8(file_memory, attributes.size), attributes); @@ -1404,7 +1243,7 @@ Panel_Split(Application_Links *app, Panel_ID panel_id, Panel_Split_Orientation o Panel *new_panel = 0; if (layout_split_panel(layout, panel, (orientation == PanelSplit_LeftAndRight), &new_panel)){ Live_Views *live_set = &models->live_set; - View *new_view = live_set_alloc_view(&models->mem.heap, &models->lifetime_allocator, live_set, new_panel); + View *new_view = live_set_alloc_view(&models->lifetime_allocator, live_set, new_panel); view_set_file(models->system, models, new_view, models->scratch_buffer); result = true; } @@ -1542,7 +1381,7 @@ View_Close(Application_Links *app, View_ID view_id) b32 result = false; if (api_check_view(view)){ if (layout_close_panel(layout, view->panel)){ - live_set_free_view(&models->mem.heap, &models->lifetime_allocator, &models->live_set, view); + live_set_free_view(&models->lifetime_allocator, &models->live_set, view); result = true; } } @@ -1902,19 +1741,21 @@ View_Get_Quit_UI_Handler(Application_Links *app, View_ID view_id, UI_Quit_Functi internal Dynamic_Workspace* get_dynamic_workspace(Models *models, Managed_Scope handle){ - u32_Ptr_Lookup_Result lookup_result = lookup_u32_Ptr_table(&models->lifetime_allocator.scope_id_to_scope_ptr_table, (u32)handle); - if (!lookup_result.success){ - return(0); + Dynamic_Workspace *result = 0; + Table_Lookup lookup = table_lookup(&models->lifetime_allocator.scope_id_to_scope_ptr_table, handle); + if (lookup.found_match){ + u64 val = 0; + table_read(&models->lifetime_allocator.scope_id_to_scope_ptr_table, lookup, &val); + result = (Dynamic_Workspace*)IntAsPtr(val); } - return((Dynamic_Workspace*)*lookup_result.val); + return(result); } API_EXPORT Managed_Scope Create_User_Managed_Scope(Application_Links *app) { Models *models = (Models*)app->cmd_context; - Heap *heap = &models->mem.heap; - Lifetime_Object *object = lifetime_alloc_object(heap, &models->lifetime_allocator, DynamicWorkspace_Unassociated, 0); + Lifetime_Object *object = lifetime_alloc_object(&models->lifetime_allocator, DynamicWorkspace_Unassociated, 0); object->workspace.user_back_ptr = object; Managed_Scope scope = (Managed_Scope)object->workspace.scope_id; return(scope); @@ -1928,7 +1769,7 @@ Destroy_User_Managed_Scope(Application_Links *app, Managed_Scope scope) b32 result = false; if (workspace != 0 && workspace->user_type == DynamicWorkspace_Unassociated){ Lifetime_Object *lifetime_object = (Lifetime_Object*)workspace->user_back_ptr; - lifetime_free_object(&models->mem.heap, &models->lifetime_allocator, lifetime_object); + lifetime_free_object(&models->lifetime_allocator, lifetime_object); result = true; } return(result); @@ -2045,8 +1886,7 @@ Get_Managed_Scope_With_Multiple_Dependencies(Application_Links *app, Managed_Sco index += 1; } member_count = lifetime_sort_and_dedup_object_set(object_ptr_array, member_count); - Heap *heap = &models->mem.heap; - Lifetime_Key *key = lifetime_get_or_create_intersection_key(heap, lifetime_allocator, object_ptr_array, member_count); + Lifetime_Key *key = lifetime_get_or_create_intersection_key(lifetime_allocator, object_ptr_array, member_count); result = (Managed_Scope)key->dynamic_workspace.scope_id; } @@ -2062,7 +1902,7 @@ Managed_Scope_Clear_Contents(Application_Links *app, Managed_Scope scope) Dynamic_Workspace *workspace = get_dynamic_workspace(models, scope); b32 result = false; if (workspace != 0){ - dynamic_workspace_clear_contents(&models->mem.heap, workspace); + dynamic_workspace_clear_contents(workspace); result = true; } return(result); @@ -2077,74 +1917,60 @@ Managed_Scope_Clear_Self_All_Dependent_Scopes(Application_Links *app, Managed_Sc if (workspace != 0 && workspace->user_type != DynamicWorkspace_Global && workspace->user_type != DynamicWorkspace_Intersected){ Lifetime_Object *object = get_lifetime_object_from_workspace(workspace); Assert(object != 0); - lifetime_object_reset(&models->mem.heap, &models->lifetime_allocator, object); + lifetime_object_reset(&models->lifetime_allocator, object); result = true; } return(result); } -API_EXPORT Managed_Variable_ID -Managed_Variable_Create(Application_Links *app, char *null_terminated_name, u64 default_value) +API_EXPORT Base_Allocator* +Managed_Scope_Allocator(Application_Links *app, Managed_Scope scope) { Models *models = (Models*)app->cmd_context; - Heap *heap = &models->mem.heap; - Dynamic_Variable_Layout *layout = &models->variable_layout; - return(dynamic_variables_create(heap, layout, SCu8(null_terminated_name), default_value)); -} - -API_EXPORT Managed_Variable_ID -Managed_Variable_Get_ID(Application_Links *app, char *null_terminated_name) -{ - Models *models = (Models*)app->cmd_context; - Dynamic_Variable_Layout *layout = &models->variable_layout; - return(dynamic_variables_lookup(layout, SCu8(null_terminated_name))); -} - -API_EXPORT Managed_Variable_ID -Managed_Variable_Create_Or_Get_ID(Application_Links *app, char *null_terminated_name, u64 default_value) -{ - Models *models = (Models*)app->cmd_context; - Heap *heap = &models->mem.heap; - Dynamic_Variable_Layout *layout = &models->variable_layout; - return(dynamic_variables_lookup_or_create(heap, layout, SCu8(null_terminated_name), default_value)); -} - -internal b32 -get_dynamic_variable__internal(Models *models, Managed_Scope handle, i32 location, u64 **ptr_out){ - Heap *heap = &models->mem.heap; - Dynamic_Variable_Layout *layout = &models->variable_layout; - Dynamic_Workspace *workspace = get_dynamic_workspace(models, handle); - b32 result = false; + Dynamic_Workspace *workspace = get_dynamic_workspace(models, scope); + Base_Allocator *result = 0; if (workspace != 0){ - if (dynamic_variables_get_ptr(heap, &workspace->mem_bank, layout, &workspace->var_block, location, ptr_out)){ - result = true; + result = &workspace->heap_wrapper; + } + return(result); +} + +API_EXPORT Managed_ID +Managed_Id_Declare(Application_Links *app, String_Const_u8 name) +{ + Models *models = (Models*)app->cmd_context; + Managed_ID_Set *set = &models->managed_id_set; + return(managed_ids_declare(set, name)); +} + +API_EXPORT void* +Managed_Scope_Get_Attachment(Application_Links *app, Managed_Scope scope, Managed_ID id, umem size){ + Models *models = (Models*)app->cmd_context; + Dynamic_Workspace *workspace = get_dynamic_workspace(models, scope); + void *result = 0; + if (workspace != 0){ + Dynamic_Variable_Block *var_block = &workspace->var_block; + Data data = dynamic_variable_get(var_block, id, size); + if (data.size >= size){ + result = data.data; + } + else{ +#define M \ + "ERROR: scope attachment already exists with a size smaller than the requested size; no attachment pointer can returned." + print_message(app, string_u8_litexpr(M)); } } return(result); } -API_EXPORT b32 -Managed_Variable_Set(Application_Links *app, Managed_Scope scope, Managed_Variable_ID id, u64 value) -{ +API_EXPORT void* +Managed_Scope_Attachment_Erase(Application_Links *app, Managed_Scope scope, Managed_ID id){ Models *models = (Models*)app->cmd_context; - u64 *ptr = 0; - b32 result = false; - if (get_dynamic_variable__internal(models, scope, id, &ptr)){ - *ptr = value; - result = true; - } - return(result); -} - -API_EXPORT b32 -Managed_Variable_Get(Application_Links *app, Managed_Scope scope, Managed_Variable_ID id, u64 *value_out) -{ - Models *models = (Models*)app->cmd_context; - u64 *ptr = 0; - b32 result = false; - if (get_dynamic_variable__internal(models, scope, id, &ptr)){ - *value_out = *ptr; - result = true; + Dynamic_Workspace *workspace = get_dynamic_workspace(models, scope); + void *result = 0; + if (workspace != 0){ + Dynamic_Variable_Block *var_block = &workspace->var_block; + dynamic_variable_erase(var_block, id); } return(result); } @@ -2156,7 +1982,7 @@ Alloc_Managed_Memory_In_Scope(Application_Links *app, Managed_Scope scope, i32 i Dynamic_Workspace *workspace = get_dynamic_workspace(models, scope); Managed_Object result = 0; if (workspace != 0){ - result = managed_object_alloc_managed_memory(&models->mem.heap, workspace, item_size, count, 0); + result = managed_object_alloc_managed_memory(workspace, item_size, count, 0); } return(result); } @@ -2176,18 +2002,7 @@ Alloc_Buffer_Markers_On_Buffer(Application_Links *app, Buffer_ID buffer_id, i32 Dynamic_Workspace *workspace = get_dynamic_workspace(models, markers_scope); Managed_Object result = 0; if (workspace != 0){ - result = managed_object_alloc_buffer_markers(&models->mem.heap, workspace, buffer_id, count, 0); - } - return(result); -} - -API_EXPORT Managed_Object -Alloc_Managed_Arena_In_Scope(Application_Links *app, Managed_Scope scope, i32 page_size){ - Models *models = (Models*)app->cmd_context; - Dynamic_Workspace *workspace = get_dynamic_workspace(models, scope); - Managed_Object result = 0; - if (workspace != 0){ - result = managed_object_alloc_managed_arena_in_scope(&models->mem.heap, workspace, app, page_size, 0); + result = managed_object_alloc_buffer_markers(workspace, buffer_id, count, 0); } return(result); } @@ -2232,6 +2047,14 @@ Managed_Object_Get_Item_Count(Application_Links *app, Managed_Object object) return(result); } +API_EXPORT void* +Managed_Object_Get_Pointer(Application_Links *app, Managed_Object object) +{ + Models *models = (Models*)app->cmd_context; + Managed_Object_Ptr_And_Workspace object_ptrs = get_dynamic_object_ptrs(models, object); + return(get_dynamic_object_memory_ptr(object_ptrs.header)); +} + API_EXPORT Managed_Object_Type Managed_Object_Get_Type(Application_Links *app, Managed_Object object) { @@ -2272,6 +2095,7 @@ Managed_Object_Free(Application_Links *app, Managed_Object object) return(result); } +// TODO(allen): ELIMINATE STORE & LOAD API_EXPORT b32 Managed_Object_Store_Data(Application_Links *app, Managed_Object object, u32 first_index, u32 count, void *mem) { @@ -2284,7 +2108,7 @@ Managed_Object_Store_Data(Application_Links *app, Managed_Object object, u32 fir if (0 <= first_index && first_index + count <= item_count){ u32 item_size = object_ptrs.header->item_size; memcpy(ptr + first_index*item_size, mem, count*item_size); - heap_assert_good(&object_ptrs.workspace->mem_bank.heap); + heap_assert_good(&object_ptrs.workspace->heap); result = true; } } @@ -2303,7 +2127,7 @@ Managed_Object_Load_Data(Application_Links *app, Managed_Object object, u32 firs if (0 <= first_index && first_index + count <= item_count){ u32 item_size = object_ptrs.header->item_size; memcpy(mem_out, ptr + first_index*item_size, count*item_size); - heap_assert_good(&object_ptrs.workspace->mem_bank.heap); + heap_assert_good(&object_ptrs.workspace->heap); result = true; } } diff --git a/4ed_app_models.h b/4ed_app_models.h index 3c793feb..5ef7cb6d 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -58,10 +58,10 @@ struct Models{ Hook_Function *hooks[hook_type_count]; Start_Hook_Function *hook_start; - Open_File_Hook_Function *hook_open_file; - Open_File_Hook_Function *hook_new_file; - Open_File_Hook_Function *hook_save_file; - Open_File_Hook_Function *hook_end_file; + Buffer_Hook_Function *hook_open_file; + Buffer_Hook_Function *hook_new_file; + Buffer_Hook_Function *hook_save_file; + Buffer_Hook_Function *hook_end_file; File_Edit_Range_Function *hook_file_edit_range; File_Edit_Finished_Function *hook_file_edit_finished; File_Externally_Modified_Function *hook_file_externally_modified; @@ -85,7 +85,7 @@ struct Models{ Text_Layout_Container text_layouts; Font_Set font_set; - Dynamic_Variable_Layout variable_layout; + Managed_ID_Set managed_id_set; Dynamic_Workspace dynamic_workspace; Lifetime_Allocator lifetime_allocator; diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index 4a069377..85888e12 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -30,9 +30,6 @@ #include "4coder_hash_functions.cpp" #include "4coder_table.cpp" -#include "4coder_lib/4coder_heap.cpp" -#define FSTRING_IMPLEMENTATION -#include "4coder_lib/4coder_string.h" #include "4coder_lib/4coder_utf8.h" // TODO(allen): stop this nonsense @@ -49,8 +46,6 @@ struct Mem_Options{ #define FCPP_FORBID_MALLOC #include "4coder_lib/4cpp_lexer.h" -#include "4ed_ptr_check.h" -#include "4ed_memory_bank.h" #include "4ed_dynamic_variables.h" #include "4ed_buffer_model.h" @@ -78,10 +73,7 @@ struct Mem_Options{ #include "4coder_log.cpp" #include "4ed_coroutine.cpp" #include "4ed_mem.cpp" -#include "4ed_ptr_check.cpp" -#include "4ed_memory_bank.cpp" #include "4ed_dynamic_variables.cpp" -#include "4ed_parse_context.cpp" #include "4ed_font_face.cpp" #include "4ed_font_set.cpp" #include "4ed_translation.cpp" @@ -90,7 +82,6 @@ struct Mem_Options{ #include "4ed_buffer.cpp" #include "4ed_string_matching.cpp" #include "4ed_history.cpp" -#include "4ed_file_lex.cpp" #include "4ed_file.cpp" #include "4ed_working_set.cpp" #include "4ed_hot_directory.cpp" diff --git a/4ed_cli.cpp b/4ed_cli.cpp index cabdc467..f0e0422f 100644 --- a/4ed_cli.cpp +++ b/4ed_cli.cpp @@ -10,18 +10,20 @@ // TOP internal void -child_process_container_init(Child_Process_Container *container, Models *models){ - container->arena = make_arena_app_links(&models->app_links); +child_process_container_init(Base_Allocator *allocator, Child_Process_Container *container){ + container->arena = make_arena(allocator); dll_init_sentinel(&container->child_process_active_list); dll_init_sentinel(&container->child_process_free_list); + container->active_child_process_count = 0; container->child_process_id_counter = 0; - block_zero_struct(&container->id_to_ptr_table); + container->id_to_ptr_table = make_table_u64_u64(allocator, 10); + container->id_to_return_code_table = make_table_u64_u64(allocator, 10); } internal void child_process_container_release(Child_Process_Container *container, Models *models){ linalloc_clear(&container->arena); - heap_free(&models->mem.heap, container->id_to_ptr_table.mem); + table_free(&container->id_to_ptr_table); block_zero_struct(container); } @@ -42,7 +44,7 @@ child_process_alloc_new(Models *models, Child_Process_Container *container){ block_zero_struct(new_process); dll_insert_back(&container->child_process_active_list, &new_process->node); new_process->id = new_id; - insert_u32_Ptr_table(&models->mem.heap, &container->id_to_ptr_table, new_id, new_process); + table_insert(&container->id_to_ptr_table, new_id, (u64)PtrAsInt(new_process)); container->active_child_process_count += 1; result.process = new_process; @@ -52,8 +54,13 @@ child_process_alloc_new(Models *models, Child_Process_Container *container){ internal Child_Process* child_process_from_id(Child_Process_Container *container, Child_Process_ID id){ + Table_Lookup lookup = table_lookup(&container->id_to_ptr_table, id); Child_Process *process = 0; - lookup_u32_Ptr_table(&container->id_to_ptr_table, &id, (void**)&process); + if (lookup.found_match){ + u64 val = 0; + table_read(&container->id_to_ptr_table, lookup, &val); + process = (Child_Process*)IntAsPtr(val); + } return(process); } @@ -62,7 +69,7 @@ child_process_free(Child_Process_Container *container, Child_Process_ID id){ b32 result = false; Child_Process *process = child_process_from_id(container, id); if (process != 0){ - erase_u32_Ptr_table(&container->id_to_ptr_table, &id); + table_erase(&container->id_to_ptr_table, id); dll_remove(&process->node); dll_insert(&container->child_process_free_list, &process->node); container->active_child_process_count -= 1; @@ -73,17 +80,16 @@ child_process_free(Child_Process_Container *container, Child_Process_ID id){ internal b32 child_process_set_return_code(Models *models, Child_Process_Container *container, Child_Process_ID id, i64 val){ - void *val_as_ptr = IntAsPtr(val); - insert_u32_Ptr_table(&models->mem.heap, &container->id_to_return_code_table, id, val_as_ptr); + table_insert(&container->id_to_return_code_table, id, val); return(true); } internal b32 child_process_lookup_return_code(Child_Process_Container *container, Child_Process_ID id, i64 *out){ b32 result = false; - void *val_as_ptr = 0; - if (lookup_u32_Ptr_table(&container->id_to_return_code_table, &id, &val_as_ptr)){ - *out = (u64)PtrAsInt(val_as_ptr); + Table_Lookup lookup = table_lookup(&container->id_to_return_code_table, id); + if (lookup.found_match){ + table_read(&container->id_to_return_code_table, lookup, (u64*)out); result = true; } return(result); diff --git a/4ed_cli.h b/4ed_cli.h index 7c39cc3a..701f07a0 100644 --- a/4ed_cli.h +++ b/4ed_cli.h @@ -26,8 +26,8 @@ struct Child_Process_Container{ Node child_process_free_list; i32 active_child_process_count; u32 child_process_id_counter; - u32_Ptr_Table id_to_ptr_table; - u32_Ptr_Table id_to_return_code_table; + Table_u64_u64 id_to_ptr_table; + Table_u64_u64 id_to_return_code_table; }; struct Child_Process_And_ID{ diff --git a/4ed_dynamic_variables.cpp b/4ed_dynamic_variables.cpp index 36023c91..d177048d 100644 --- a/4ed_dynamic_variables.cpp +++ b/4ed_dynamic_variables.cpp @@ -10,413 +10,147 @@ // TOP internal void -dynamic_variables_init(Dynamic_Variable_Layout *layout){ - dll_init_sentinel(&layout->sentinel); - layout->location_counter = 1; +managed_ids_init(Base_Allocator *allocator, Managed_ID_Set *set){ + set->arena = make_arena(allocator, KB(4), 8); + set->name_to_id_table = make_table_Data_u64(allocator, 40); + set->id_counter = 1; } -internal Managed_Variable_ID -dynamic_variables_lookup(Dynamic_Variable_Layout *layout, String_Const_u8 name){ - for (Dynamic_Variable_Slot *slot = layout->sentinel.next; - slot != &layout->sentinel; - slot = slot->next){ - if (string_match(slot->name, name)){ - return(slot->location); - } - } - return(ManagedVariableIndex_ERROR); -} - -internal Managed_Variable_ID -dynamic_variables_create__always(Heap *heap, Dynamic_Variable_Layout *layout, String_Const_u8 name, u64 default_value){ - i32 alloc_size = (i32)(name.size + 1 + sizeof(Dynamic_Variable_Slot)); - void *ptr = heap_allocate(heap, alloc_size); - Managed_Variable_ID result = ManagedVariableIndex_ERROR; - if (ptr != 0){ - Dynamic_Variable_Slot *new_slot = (Dynamic_Variable_Slot*)ptr; - char *c_str = (char*)(new_slot + 1); - block_copy(c_str, name.str, name.size); - c_str[name.size] = 0; - new_slot->name = SCu8(c_str, name.size); - new_slot->default_value = default_value; - new_slot->location = layout->location_counter++; - dll_insert_back(&layout->sentinel, new_slot); - result = new_slot->location; - } - return(result); -} - -internal Managed_Variable_ID -dynamic_variables_lookup_or_create(Heap *heap, Dynamic_Variable_Layout *layout, String_Const_u8 name, u64 default_value){ - Managed_Variable_ID lookup_id = dynamic_variables_lookup(layout, name); - if (lookup_id == ManagedVariableIndex_ERROR){ - lookup_id = dynamic_variables_create__always(heap, layout, name, default_value); - } - return(lookup_id); -} - -internal i32 -dynamic_variables_create(Heap *heap, Dynamic_Variable_Layout *layout, String_Const_u8 name, u64 default_value){ - Managed_Variable_ID lookup_id = dynamic_variables_lookup(layout, name); - if (lookup_id == ManagedVariableIndex_ERROR){ - return(dynamic_variables_create__always(heap, layout, name, default_value)); - } - return(ManagedVariableIndex_ERROR); -} - -//////////////////////////////// - -internal void -dynamic_variables_block_init(Dynamic_Variable_Block *block){ - block->val_array = 0; - block->count = 0; - block->max = 0; -} - -internal void -dynamic_variables_block_grow_max_to(Heap *heap, Memory_Bank *mem_bank, i32 new_max, Dynamic_Variable_Block *block){ - i32 new_size = new_max*sizeof(u64); - u64 *new_array = (u64*)memory_bank_allocate(heap, mem_bank, new_size); - if (block->val_array != 0){ - memcpy(new_array, block->val_array, sizeof(u64)*block->count); - memory_bank_free(mem_bank, block->val_array); - } - block->val_array = new_array; -} - -internal void -dynamic_variables_block_fill_unset_values(Dynamic_Variable_Layout *layout, Dynamic_Variable_Block *block, i32 one_past_last_index){ - i32 first_location = block->count + 1; - i32 one_past_last_location = one_past_last_index + 1; - block->count = one_past_last_index; - for (Dynamic_Variable_Slot *slot = layout->sentinel.next; - slot != &layout->sentinel; - slot = slot->next){ - if (first_location <= slot->location && slot->location < one_past_last_location){ - block->val_array[slot->location - 1] = slot->default_value; - } - } -} - -internal b32 -dynamic_variables_get_ptr(Heap *heap, Memory_Bank *mem_bank, - Dynamic_Variable_Layout *layout, Dynamic_Variable_Block *block, - i32 location, u64 **ptr_out){ - b32 result = false; - if (location > 0 && location < layout->location_counter){ - i32 index = location - 1; - if (index >= block->count){ - i32 minimum_max = layout->location_counter - 1; - if (block->max < minimum_max){ - dynamic_variables_block_grow_max_to(heap, mem_bank, minimum_max*2, block); - } - dynamic_variables_block_fill_unset_values(layout, block, index + 1); - } - *ptr_out = block->val_array + index; - result = true; - } - return(result); -} - -//////////////////////////////// - -internal void -insert_u32_Ptr_table(Heap *heap, Memory_Bank *mem_bank, u32_Ptr_Table *table, u32 key, void* val){ - if (at_max_u32_Ptr_table(table)){ - i32 new_max = (table->max + 1)*2; - i32 new_mem_size = max_to_memsize_u32_Ptr_table(new_max); - void *new_mem = memory_bank_allocate(heap, mem_bank, new_mem_size); - u32_Ptr_Table new_table = make_u32_Ptr_table(new_mem, new_mem_size); - if (table->mem != 0){ - b32 result = move_u32_Ptr_table(&new_table, table); - Assert(result); - memory_bank_free(mem_bank, table->mem); - } - *table = new_table; - } - b32 result = insert_u32_Ptr_table(table, &key, &val); - Assert(result); -} - -//////////////////////////////// - -internal void -marker_visual_allocator_init(Marker_Visual_Allocator *allocator){ - memset(allocator, 0, sizeof(*allocator)); -} - -internal Marker_Visual_Data* -dynamic_workspace_alloc_visual(Heap *heap, Memory_Bank *mem_bank, Dynamic_Workspace *workspace){ - Marker_Visual_Allocator *allocator = &workspace->visual_allocator; - if (allocator->free_count == 0){ - i32 new_slots_count = clamp_bot(16, allocator->total_visual_count); - i32 memsize = new_slots_count*sizeof(Marker_Visual_Data); - void *new_slots_memory = memory_bank_allocate(heap, mem_bank, memsize); - memset(new_slots_memory, 0, memsize); - Marker_Visual_Data *new_slot = (Marker_Visual_Data*)new_slots_memory; - allocator->free_count += new_slots_count; - allocator->total_visual_count += new_slots_count; - for (i32 i = 0; i < new_slots_count; i += 1, new_slot += 1){ - zdll_push_back(allocator->free_first, allocator->free_last, new_slot); - new_slot->slot_id = ++workspace->visual_id_counter; - insert_u32_Ptr_table(heap, mem_bank, &allocator->id_to_ptr_table, new_slot->slot_id, new_slot); - } - } - Marker_Visual_Data *data = allocator->free_first; - zdll_remove(allocator->free_first, allocator->free_last, data); - allocator->free_count -= 1; - data->gen_id += 1; - return(data); -} - -internal void -marker_visual_free(Marker_Visual_Allocator *allocator, Marker_Visual_Data *data){ - zdll_push_back(allocator->free_first, allocator->free_last, data); - allocator->free_count += 1; -} - -internal void -marker_visual_free_chain(Marker_Visual_Allocator *allocator, Marker_Visual_Data *first, Marker_Visual_Data *last, i32 count){ - if (allocator->free_first == 0){ - allocator->free_first = first; - allocator->free_last = last; +internal Managed_ID +managed_ids_declare(Managed_ID_Set *set, String_Const_u8 name){ + Managed_ID result = 0; + Data data = make_data(name.str, name.size); + Table_Lookup lookup = table_lookup(&set->name_to_id_table, data); + if (lookup.found_match){ + table_read(&set->name_to_id_table, lookup, &result); } else{ - allocator->free_last->next = first; - first->prev = allocator->free_last; - allocator->free_last = last; + result = set->id_counter; + set->id_counter += 1; + data = push_data_copy(&set->arena, data); + table_insert(&set->name_to_id_table, data, result); } - allocator->free_count += count; -} - -internal void -marker_visual_defaults(Marker_Visual_Data *data){ - data->type = VisualType_Invisible; - data->color = 0; - data->text_color = 0; - data->text_style = 0; - data->take_rule.first_index = 0; - data->take_rule.take_count_per_step = 1; - data->take_rule.step_stride_in_marker_count = 1; - data->take_rule.maximum_number_of_markers = max_i32; - data->one_past_last_take_index = max_i32; - data->priority = VisualPriority_Default; - data->key_view_id = 0; + return(result); } //////////////////////////////// internal void -dynamic_workspace_init(Heap *heap, Lifetime_Allocator *lifetime_allocator, i32 user_type, void *user_back_ptr, Dynamic_Workspace *workspace){ - memset(workspace, 0, sizeof(*workspace)); - memory_bank_init(&workspace->mem_bank); - dynamic_variables_block_init(&workspace->var_block); - marker_visual_allocator_init(&workspace->visual_allocator); +dynamic_variable_block_init(Base_Allocator *allocator, Dynamic_Variable_Block *block){ + block->arena = make_arena(allocator, KB(4), 8); + block->id_to_data_table = make_table_u64_Data(allocator, 20); +} + +internal Data +dynamic_variable_get(Dynamic_Variable_Block *block, Managed_ID id, umem size){ + Data result = {}; + Table_Lookup lookup = table_lookup(&block->id_to_data_table, id); + if (lookup.found_match){ + table_read(&block->id_to_data_table, lookup, &result); + } + else{ + result = push_data(&block->arena, size); + block_zero(result); + table_insert(&block->id_to_data_table, id, result); + } + return(result); +} + +internal void +dynamic_variable_erase(Dynamic_Variable_Block *block, Managed_ID id){ + table_erase(&block->id_to_data_table, id); +} + +//////////////////////////////// + +internal void +lifetime_allocator_init(Base_Allocator *base_allocator, Lifetime_Allocator *lifetime_allocator){ + block_zero_struct(lifetime_allocator); + lifetime_allocator->allocator = base_allocator; + lifetime_allocator->key_table = make_table_Data_u64(base_allocator, 100); + lifetime_allocator->key_check_table = make_table_u64_u64(base_allocator, 100); + lifetime_allocator->scope_id_to_scope_ptr_table = make_table_u64_u64(base_allocator, 100); +} + +//////////////////////////////// + +internal void +dynamic_workspace_init(Lifetime_Allocator *lifetime_allocator, i32 user_type, void *user_back_ptr, Dynamic_Workspace *workspace){ + block_zero_struct(workspace); + heap_init(&workspace->heap, lifetime_allocator->allocator); + workspace->heap_wrapper = base_allocator_on_heap(&workspace->heap); + workspace->object_id_to_object_ptr = make_table_u64_u64(&workspace->heap_wrapper, 10); + dynamic_variable_block_init(&workspace->heap_wrapper, &workspace->var_block); if (lifetime_allocator->scope_id_counter == 0){ lifetime_allocator->scope_id_counter = 1; } workspace->scope_id = lifetime_allocator->scope_id_counter++; - insert_u32_Ptr_table(heap, &lifetime_allocator->scope_id_to_scope_ptr_table, workspace->scope_id, workspace); + table_insert(&lifetime_allocator->scope_id_to_scope_ptr_table, + workspace->scope_id, (u64)PtrAsInt(workspace)); workspace->user_type = user_type; workspace->user_back_ptr = user_back_ptr; } internal void -dynamic_workspace_free(Heap *heap, Lifetime_Allocator *lifetime_allocator, Dynamic_Workspace *workspace){ - erase_u32_Ptr_table(&lifetime_allocator->scope_id_to_scope_ptr_table, workspace->scope_id); - memory_bank_free_all(heap, &workspace->mem_bank); +dynamic_workspace_free(Lifetime_Allocator *lifetime_allocator, Dynamic_Workspace *workspace){ + table_erase(&lifetime_allocator->scope_id_to_scope_ptr_table, workspace->scope_id); + heap_free_all(&workspace->heap); } internal void -dynamic_workspace_clear_contents(Heap *heap, Dynamic_Workspace *workspace){ - memory_bank_free_all(heap, &workspace->mem_bank); - memory_bank_init(&workspace->mem_bank); - - dynamic_variables_block_init(&workspace->var_block); - marker_visual_allocator_init(&workspace->visual_allocator); - memset(&workspace->object_id_to_object_ptr, 0, sizeof(workspace->object_id_to_object_ptr)); - memset(&workspace->buffer_markers_list, 0, sizeof(workspace->buffer_markers_list)); +dynamic_workspace_clear_contents(Dynamic_Workspace *workspace){ + Base_Allocator *base_allocator = heap_free_all(&workspace->heap); + heap_init(&workspace->heap, base_allocator); + workspace->heap_wrapper = base_allocator_on_heap(&workspace->heap); + workspace->object_id_to_object_ptr = make_table_u64_u64(&workspace->heap_wrapper, 10); + dynamic_variable_block_init(&workspace->heap_wrapper, &workspace->var_block); + block_zero_struct(&workspace->buffer_markers_list); workspace->total_marker_count = 0; } internal u32 -dynamic_workspace_store_pointer(Heap *heap, Dynamic_Workspace *workspace, void *ptr){ +dynamic_workspace_store_pointer(Dynamic_Workspace *workspace, void *ptr){ if (workspace->object_id_counter == 0){ workspace->object_id_counter = 1; } u32 id = workspace->object_id_counter++; - insert_u32_Ptr_table(heap, &workspace->mem_bank, &workspace->object_id_to_object_ptr, id, ptr); + table_insert(&workspace->object_id_to_object_ptr, id, (u64)PtrAsInt(ptr)); return(id); } internal void dynamic_workspace_erase_pointer(Dynamic_Workspace *workspace, u32 id){ - erase_u32_Ptr_table(&workspace->object_id_to_object_ptr, id); + table_erase(&workspace->object_id_to_object_ptr, id); } internal void* dynamic_workspace_get_pointer(Dynamic_Workspace *workspace, u32 id){ - u32_Ptr_Lookup_Result lookup = lookup_u32_Ptr_table(&workspace->object_id_to_object_ptr, id); - if (lookup.success){ - return(*lookup.val); + void *result = 0; + Table_Lookup lookup = table_lookup(&workspace->object_id_to_object_ptr, id); + if (lookup.found_match){ + u64 val = 0; + table_read(&workspace->object_id_to_object_ptr, lookup, &val); + result = IntAsPtr(val); } - return(0); -} - -internal Marker_Visual_Data* -dynamic_workspace_get_visual_pointer(Dynamic_Workspace *workspace, u32 slot_id, u32 gen_id){ - void *data_ptr = 0; - if (lookup_u32_Ptr_table(&workspace->visual_allocator.id_to_ptr_table, slot_id, &data_ptr)){ - Marker_Visual_Data *data = (Marker_Visual_Data*)data_ptr; - if (data->gen_id == gen_id){ - void *object_ptr = dynamic_workspace_get_pointer(workspace, data->owner_object&max_u32); - if (object_ptr != 0){ - return(data); - } - } - } - return(0); + return(result); } //////////////////////////////// -internal u64 -lifetime__key_hash(Lifetime_Object **object_ptr_array, i32 count){ - u64 hash = bit_1; - for (i32 i = 0; i < count; i += 1){ - u64 x = (u64)(PtrAsInt(object_ptr_array[i])); - x >>= 3; - hash = (hash + ((hash << 37) ^ (((x) >> (x&1))))); - } - return(hash | bit_63); +internal Data +lifetime__key_as_data(Lifetime_Object **members, i32 count){ + return(make_data(members, sizeof(*members)*count)); } -internal Lifetime_Key* -lifetime__key_table_lookup(Lifetime_Key_Table *table, u64 hash, Lifetime_Object **object_ptr_array, i32 count){ - u32 max = table->max; - if (max > 0 && table->count > 0){ - u32 first_index = hash%max; - u32 index = first_index; - u64 *hashes = table->hashes; - umem set_size = count*sizeof(Lifetime_Object*); - for (;;){ - if (hashes[index] == hash){ - Lifetime_Key *key = table->keys[index]; - if (key->count == count && - memcmp(object_ptr_array, key->members, set_size) == 0){ - return(key); - } - } - else if (hashes[index] == LifetimeKeyHash_Empty){ - return(0); - } - index += 1; - if (index == max){ - index = 0; - } - if (index == first_index){ - return(0); - } - } - } - return(0); -} - -internal Lifetime_Key_Table -lifetime__key_table_copy(Heap *heap, Lifetime_Key_Table table, u32 new_max); - -internal void -lifetime__key_table_insert(Heap *heap, Lifetime_Key_Table *table, u64 hash, Lifetime_Key *key){ - { - u32 max = table->max; - u32 count = table->count; - if (max == 0 || (count + 1)*6 > max*5){ - Assert(heap != 0); - Lifetime_Key_Table new_table = lifetime__key_table_copy(heap, *table, max*2); - heap_free(heap, table->mem_ptr); - *table = new_table; - } - } - - { - u32 max = table->max; - if (max > 0){ - u32 first_index = hash%max; - u32 index = first_index; - u64 *hashes = table->hashes; - for (;;){ - if (hashes[index] == LifetimeKeyHash_Empty || - hashes[index] == LifetimeKeyHash_Deleted){ - hashes[index] = hash; - table->keys[index] = key; - table->count += 1; - return; - } - index += 1; - if (index == max){ - index = 0; - } - if (index == first_index){ - return; - } - } - } - } +internal Data +lifetime__key_as_data(Lifetime_Key *key){ + return(lifetime__key_as_data(key->members, key->count)); } internal void -lifetime__key_table_erase(Lifetime_Key_Table *table, Lifetime_Key *erase_key){ - u32 max = table->max; - if (max > 0 && table->count > 0){ - u64 hash = lifetime__key_hash(erase_key->members, erase_key->count); - u32 first_index = hash%max; - u32 index = first_index; - u64 *hashes = table->hashes; - for (;;){ - if (hashes[index] == hash){ - Lifetime_Key *key = table->keys[index]; - if (erase_key == key){ - hashes[index] = LifetimeKeyHash_Deleted; - table->keys[index] = 0; - return; - } - } - else if (hashes[index] == LifetimeKeyHash_Empty){ - return; - } - index += 1; - if (index == max){ - index = 0; - } - if (index == first_index){ - return; - } - } - } -} - -internal Lifetime_Key_Table -lifetime__key_table_copy(Heap *heap, Lifetime_Key_Table table, u32 new_max){ - Lifetime_Key_Table new_table = {}; - new_table.max = clamp_bot(table.max, new_max); - new_table.max = clamp_bot(307, new_table.max); - i32 item_size = sizeof(*new_table.hashes) + sizeof(*new_table.keys); - new_table.mem_ptr = heap_allocate(heap, item_size*new_table.max); - memset(new_table.mem_ptr, 0, item_size*new_table.max); - new_table.hashes = (u64*)(new_table.mem_ptr); - new_table.keys = (Lifetime_Key**)(new_table.hashes + new_table.max); - for (u32 i = 0; i < table.max; i += 1){ - if ((table.hashes[i]&bit_63) != 0){ - lifetime__key_table_insert(0, &new_table, table.hashes[i], table.keys[i]); - } - } - return(new_table); -} - -internal void -lifetime__free_key(Heap *heap, Lifetime_Allocator *lifetime_allocator, Lifetime_Key *key, Lifetime_Object *skip_object){ +lifetime__free_key(Lifetime_Allocator *lifetime_allocator, Lifetime_Key *key, Lifetime_Object *skip_object){ // Deinit - dynamic_workspace_free(heap, lifetime_allocator, &key->dynamic_workspace); + dynamic_workspace_free(lifetime_allocator, &key->dynamic_workspace); // Remove From Objects i32 count = key->count; @@ -458,20 +192,22 @@ lifetime__free_key(Heap *heap, Lifetime_Allocator *lifetime_allocator, Lifetime_ } // Free - lifetime__key_table_erase(&lifetime_allocator->key_table, key); - erase_Ptr_table(&lifetime_allocator->key_check_table, key); - heap_free(heap, key->members); + Data key_data = lifetime__key_as_data(key); + table_erase(&lifetime_allocator->key_table, key_data); + table_erase(&lifetime_allocator->key_check_table, (u64)PtrAsInt(key)); + base_free(lifetime_allocator->allocator, key->members); zdll_push_back(lifetime_allocator->free_keys.first, lifetime_allocator->free_keys.last, key); } internal Lifetime_Key_Ref_Node* -lifetime__alloc_key_reference_node(Heap *heap, Lifetime_Allocator *lifetime_allocator){ +lifetime__alloc_key_reference_node(Lifetime_Allocator *lifetime_allocator){ Assert(lifetime_allocator != 0); Lifetime_Key_Ref_Node *result = lifetime_allocator->free_key_references.first; if (result == 0){ i32 new_node_count = 32; - Lifetime_Key_Ref_Node *new_nodes = heap_array(heap, Lifetime_Key_Ref_Node, new_node_count); - Assert(new_nodes != 0); + umem new_memory_size = new_node_count*sizeof(Lifetime_Key_Ref_Node); + Data new_memory = base_allocate(lifetime_allocator->allocator, new_memory_size); + Lifetime_Key_Ref_Node *new_nodes = (Lifetime_Key_Ref_Node*)new_memory.data; Lifetime_Key_Ref_Node *new_node_ptr = new_nodes; for (i32 i = 0; i < new_node_count; i += 1, new_node_ptr += 1){ zdll_push_back(lifetime_allocator->free_key_references.first, @@ -486,8 +222,7 @@ lifetime__alloc_key_reference_node(Heap *heap, Lifetime_Allocator *lifetime_allo } internal void -lifetime__object_add_key(Heap *heap, Lifetime_Allocator *lifetime_allocator, - Lifetime_Object *object, Lifetime_Key *key){ +lifetime__object_add_key(Lifetime_Allocator *lifetime_allocator, Lifetime_Object *object, Lifetime_Key *key){ Lifetime_Key_Ref_Node *last_node = object->key_node_last; b32 insert_on_new_node = false; if (last_node == 0){ @@ -504,20 +239,22 @@ lifetime__object_add_key(Heap *heap, Lifetime_Allocator *lifetime_allocator, } } if (insert_on_new_node){ - Lifetime_Key_Ref_Node *new_node = lifetime__alloc_key_reference_node(heap, lifetime_allocator); + Lifetime_Key_Ref_Node *new_node = lifetime__alloc_key_reference_node(lifetime_allocator); zdll_push_back(object->key_node_first, object->key_node_last, new_node); - memset(new_node->keys, 0, sizeof(new_node->keys)); + block_zero_struct(new_node->keys); new_node->keys[0] = key; object->key_count += 1; } } internal Lifetime_Object* -lifetime_alloc_object(Heap *heap, Lifetime_Allocator *lifetime_allocator, i32 user_type, void *user_back_ptr){ +lifetime_alloc_object(Lifetime_Allocator *lifetime_allocator, i32 user_type, void *user_back_ptr){ Lifetime_Object *object = lifetime_allocator->free_objects.first; if (object == 0){ i32 new_object_count = 256; - Lifetime_Object *new_objects = heap_array(heap, Lifetime_Object, new_object_count); + umem new_memory_size = new_object_count*sizeof(Lifetime_Object); + Data new_memory = base_allocate(lifetime_allocator->allocator, new_memory_size); + Lifetime_Object *new_objects = (Lifetime_Object*)new_memory.data; Lifetime_Object *new_object_ptr = new_objects; for (i32 i = 0; i < new_object_count; i += 1, new_object_ptr += 1){ zdll_push_back(lifetime_allocator->free_objects.first, lifetime_allocator->free_objects.last, new_object_ptr); @@ -529,21 +266,21 @@ lifetime_alloc_object(Heap *heap, Lifetime_Allocator *lifetime_allocator, i32 us zdll_remove(lifetime_allocator->free_objects.first, lifetime_allocator->free_objects.last, object); lifetime_allocator->free_objects.count -= 1; - memset(object, 0, sizeof(*object)); - dynamic_workspace_init(heap, lifetime_allocator, user_type, user_back_ptr, &object->workspace); + block_zero_struct(object); + dynamic_workspace_init(lifetime_allocator, user_type, user_back_ptr, &object->workspace); return(object); } internal void -lifetime__object_free_all_keys(Heap *heap, Lifetime_Allocator *lifetime_allocator, Lifetime_Object *lifetime_object){ +lifetime__object_free_all_keys(Lifetime_Allocator *lifetime_allocator, Lifetime_Object *lifetime_object){ i32 key_i = 0; for (Lifetime_Key_Ref_Node *node = lifetime_object->key_node_first; node != 0; node = node->next){ i32 one_past_last = clamp_top(ArrayCount(node->keys), lifetime_object->key_count - key_i); for (i32 i = 0; i < one_past_last; i += 1){ - lifetime__free_key(heap, lifetime_allocator, node->keys[i], lifetime_object); + lifetime__free_key(lifetime_allocator, node->keys[i], lifetime_object); } key_i += one_past_last; } @@ -557,7 +294,7 @@ lifetime__object_free_all_keys(Heap *heap, Lifetime_Allocator *lifetime_allocato } internal void -lifetime__object_clear_all_keys(Heap *heap, Lifetime_Allocator *lifetime_allocator, Lifetime_Object *lifetime_object){ +lifetime__object_clear_all_keys(Lifetime_Allocator *lifetime_allocator, Lifetime_Object *lifetime_object){ i32 key_i = 0; for (Lifetime_Key_Ref_Node *node = lifetime_object->key_node_first; node != 0; @@ -565,23 +302,23 @@ lifetime__object_clear_all_keys(Heap *heap, Lifetime_Allocator *lifetime_allocat i32 one_past_last = clamp_top(ArrayCount(node->keys), lifetime_object->key_count - key_i); Lifetime_Key **key_ptr = node->keys; for (i32 i = 0; i < one_past_last; i += 1, key_ptr += 1){ - dynamic_workspace_clear_contents(heap, &(*key_ptr)->dynamic_workspace); + dynamic_workspace_clear_contents(&(*key_ptr)->dynamic_workspace); } key_i += one_past_last; } } internal void -lifetime_free_object(Heap *heap, Lifetime_Allocator *lifetime_allocator, Lifetime_Object *lifetime_object){ - lifetime__object_free_all_keys(heap, lifetime_allocator, lifetime_object); - dynamic_workspace_free(heap, lifetime_allocator, &lifetime_object->workspace); +lifetime_free_object(Lifetime_Allocator *lifetime_allocator, Lifetime_Object *lifetime_object){ + lifetime__object_free_all_keys(lifetime_allocator, lifetime_object); + dynamic_workspace_free(lifetime_allocator, &lifetime_object->workspace); zdll_push_back(lifetime_allocator->free_objects.first, lifetime_allocator->free_objects.last, lifetime_object); } internal void -lifetime_object_reset(Heap *heap, Lifetime_Allocator *lifetime_allocator, Lifetime_Object *lifetime_object){ - lifetime__object_clear_all_keys(heap, lifetime_allocator, lifetime_object); - dynamic_workspace_clear_contents(heap, &lifetime_object->workspace); +lifetime_object_reset(Lifetime_Allocator *lifetime_allocator, Lifetime_Object *lifetime_object){ + lifetime__object_clear_all_keys(lifetime_allocator, lifetime_object); + dynamic_workspace_clear_contents(&lifetime_object->workspace); } internal i32 @@ -624,21 +361,24 @@ lifetime_sort_and_dedup_object_set(Lifetime_Object **ptr_array, i32 count){ } internal Lifetime_Key* -lifetime_get_or_create_intersection_key(Heap *heap, Lifetime_Allocator *lifetime_allocator, Lifetime_Object **object_ptr_array, i32 count){ - u64 hash = lifetime__key_hash(object_ptr_array, count); - - // Lookup - Lifetime_Key *existing_key = lifetime__key_table_lookup(&lifetime_allocator->key_table, hash, - object_ptr_array, count); - if (existing_key != 0){ - return(existing_key); +lifetime_get_or_create_intersection_key(Lifetime_Allocator *lifetime_allocator, Lifetime_Object **object_ptr_array, i32 count){ + { + Data key_data = lifetime__key_as_data(object_ptr_array, count); + Table_Lookup lookup = table_lookup(&lifetime_allocator->key_table, key_data); + if (lookup.found_match){ + u64 val = 0; + table_read(&lifetime_allocator->key_table, lookup, &val); + return((Lifetime_Key*)IntAsPtr(val)); + } } // Allocate Lifetime_Key *new_key = lifetime_allocator->free_keys.first; if (new_key == 0){ i32 new_key_count = 256; - Lifetime_Key *new_keys = heap_array(heap, Lifetime_Key, new_key_count); + umem new_memory_size = new_key_count*sizeof(Lifetime_Key); + Data new_memory = base_allocate(lifetime_allocator->allocator, new_memory_size); + Lifetime_Key *new_keys = (Lifetime_Key*)new_memory.data; Lifetime_Key *new_key_ptr = new_keys; for (i32 i = 0; i < new_key_count; i += 1, new_key_ptr += 1){ zdll_push_back(lifetime_allocator->free_keys.first, lifetime_allocator->free_keys.last, new_key_ptr); @@ -647,32 +387,39 @@ lifetime_get_or_create_intersection_key(Heap *heap, Lifetime_Allocator *lifetime new_key = lifetime_allocator->free_keys.first; } zdll_remove(lifetime_allocator->free_keys.first, lifetime_allocator->free_keys.last, new_key); - memset(new_key, 0, sizeof(*new_key)); + block_zero_struct(new_key); // Add to Objects Lifetime_Object **object_ptr = object_ptr_array; for (i32 i = 0; i < count; i += 1, object_ptr += 1){ Lifetime_Object *object = *object_ptr; - lifetime__object_add_key(heap, lifetime_allocator, object, new_key); + lifetime__object_add_key(lifetime_allocator, object, new_key); } // Initialize - new_key->members = heap_array(heap, Lifetime_Object*, count); - memcpy(new_key->members, object_ptr_array, sizeof(*new_key->members)*count); + umem new_memory_size = sizeof(Lifetime_Object*)*count; + Data new_memory = base_allocate(lifetime_allocator->allocator, new_memory_size); + new_key->members = (Lifetime_Object**)new_memory.data; + block_copy_dynamic_array(new_key->members, object_ptr_array, count); new_key->count = count; - dynamic_workspace_init(heap, lifetime_allocator, + dynamic_workspace_init(lifetime_allocator, DynamicWorkspace_Intersected, new_key, &new_key->dynamic_workspace); - lifetime__key_table_insert(heap, &lifetime_allocator->key_table, hash, new_key); - insert_Ptr_table(heap, &lifetime_allocator->key_check_table, new_key); + { + Data key_data = lifetime__key_as_data(new_key); + u64 new_key_val = (u64)PtrAsInt(new_key); + table_insert(&lifetime_allocator->key_table, key_data, new_key_val); + table_insert(&lifetime_allocator->key_check_table, new_key_val, new_key_val); + } return(new_key); } internal b32 lifetime_key_check(Lifetime_Allocator *lifetime_allocator, Lifetime_Key *key){ - return(lookup_Ptr_table(&lifetime_allocator->key_check_table, key)); + Table_Lookup lookup = table_lookup(&lifetime_allocator->key_check_table, (u64)PtrAsInt(key)); + return(lookup.found_match); } //////////////////////////////// @@ -688,21 +435,16 @@ get_dynamic_object_memory_ptr(Managed_Object_Standard_Header *header){ { ptr = ((u8*)header) + managed_header_type_sizes[header->type]; }break; - case ManagedObjectType_Arena: - { - ptr = ((u8*)header) + managed_header_type_sizes[header->type]; - Managed_Arena_Header *arena_header = (Managed_Arena_Header*)header; - *(Arena**)ptr = &arena_header->arena; - }break; } } return(ptr); } internal Managed_Object -managed_object_alloc_managed_memory(Heap *heap, Dynamic_Workspace *workspace, i32 item_size, i32 count, void **ptr_out){ +managed_object_alloc_managed_memory(Dynamic_Workspace *workspace, i32 item_size, i32 count, void **ptr_out){ i32 size = item_size*count; - void *ptr = memory_bank_allocate(heap, &workspace->mem_bank, sizeof(Managed_Memory_Header) + size); + Data new_memory = base_allocate(&workspace->heap_wrapper, sizeof(Managed_Memory_Header) + size); + void *ptr = new_memory.data; Managed_Memory_Header *header = (Managed_Memory_Header*)ptr; header->std_header.type = ManagedObjectType_Memory; header->std_header.item_size = item_size; @@ -710,14 +452,15 @@ managed_object_alloc_managed_memory(Heap *heap, Dynamic_Workspace *workspace, i3 if (ptr_out != 0){ *ptr_out = get_dynamic_object_memory_ptr(&header->std_header); } - u32 id = dynamic_workspace_store_pointer(heap, workspace, ptr); + u32 id = dynamic_workspace_store_pointer(workspace, ptr); return(((u64)workspace->scope_id << 32) | (u64)id); } internal Managed_Object -managed_object_alloc_buffer_markers(Heap *heap, Dynamic_Workspace *workspace, Buffer_ID buffer_id, i32 count, Marker **markers_out){ +managed_object_alloc_buffer_markers(Dynamic_Workspace *workspace, Buffer_ID buffer_id, i32 count, Marker **markers_out){ i32 size = count*sizeof(Marker); - void *ptr = memory_bank_allocate(heap, &workspace->mem_bank, size + sizeof(Managed_Buffer_Markers_Header)); + Data new_memory = base_allocate(&workspace->heap_wrapper, size + sizeof(Managed_Buffer_Markers_Header)); + void *ptr = new_memory.data; Managed_Buffer_Markers_Header *header = (Managed_Buffer_Markers_Header*)ptr; header->std_header.type = ManagedObjectType_Markers; header->std_header.item_size = sizeof(Marker); @@ -726,29 +469,10 @@ managed_object_alloc_buffer_markers(Heap *heap, Dynamic_Workspace *workspace, Bu workspace->buffer_markers_list.count += 1; workspace->total_marker_count += count; header->buffer_id = buffer_id; - header->visual_first = 0; - header->visual_last = 0; - header->visual_count = 0; if (markers_out != 0){ *markers_out = (Marker*)get_dynamic_object_memory_ptr(&header->std_header); } - u32 id = dynamic_workspace_store_pointer(heap, workspace, ptr); - return(((u64)workspace->scope_id << 32) | (u64)id); -} - -internal Managed_Object -managed_object_alloc_managed_arena_in_scope(Heap *heap, Dynamic_Workspace *workspace, Application_Links *app, i32 page_size, Arena **arena_out){ - void *ptr = memory_bank_allocate(heap, &workspace->mem_bank, sizeof(Managed_Arena_Header) + sizeof(Arena*)); - Managed_Arena_Header *header = (Managed_Arena_Header*)ptr; - header->std_header.type = ManagedObjectType_Arena; - header->std_header.item_size = sizeof(Arena*); - header->std_header.count = 1; - zdll_push_back(workspace->arena_list.first, workspace->arena_list.last, header); - header->arena = make_arena_app_links(app, page_size); - if (arena_out != 0){ - *arena_out = &header->arena; - } - u32 id = dynamic_workspace_store_pointer(heap, workspace, ptr); + u32 id = dynamic_workspace_store_pointer(workspace, ptr); return(((u64)workspace->scope_id << 32) | (u64)id); } @@ -764,22 +488,12 @@ managed_object_free(Dynamic_Workspace *workspace, Managed_Object object){ { Managed_Buffer_Markers_Header *header = (Managed_Buffer_Markers_Header*)object_ptr; workspace->total_marker_count -= header->std_header.count; - if (header->visual_count > 0){ - marker_visual_free_chain(&workspace->visual_allocator, header->visual_first, header->visual_last, header->visual_count); - } zdll_remove(workspace->buffer_markers_list.first, workspace->buffer_markers_list.last, header); workspace->buffer_markers_list.count -= 1; }break; - - case ManagedObjectType_Arena: - { - Managed_Arena_Header *header = (Managed_Arena_Header*)object_ptr; - linalloc_clear(&header->arena); - zdll_remove(workspace->arena_list.first, workspace->arena_list.last, header); - }break; } dynamic_workspace_erase_pointer(workspace, lo_id); - memory_bank_free(&workspace->mem_bank, object_ptr); + base_free(&workspace->heap_wrapper, object_ptr); result = true; } return(result); diff --git a/4ed_dynamic_variables.h b/4ed_dynamic_variables.h index 4778740a..5cb2e4db 100644 --- a/4ed_dynamic_variables.h +++ b/4ed_dynamic_variables.h @@ -30,37 +30,6 @@ struct Managed_Buffer_Markers_Header{ Managed_Buffer_Markers_Header *next; Managed_Buffer_Markers_Header *prev; Buffer_ID buffer_id; - struct Marker_Visual_Data *visual_first; - struct Marker_Visual_Data *visual_last; - i32 visual_count; -}; - -struct Marker_Visual_Data{ - Marker_Visual_Data *next; - Marker_Visual_Data *prev; - Managed_Object owner_object; - u32 slot_id; - u32 gen_id; - // "Look" - Marker_Visual_Type type; - u32 color; - u32 text_color; - Marker_Visual_Text_Style text_style; - // "Take Rule" - Marker_Visual_Take_Rule take_rule; - i32 one_past_last_take_index; - // "Priority" - Marker_Visual_Priority_Level priority; - // "Key View ID" - View_ID key_view_id; -}; - -struct Marker_Visual_Allocator{ - Marker_Visual_Data *free_first; - Marker_Visual_Data *free_last; - i32 free_count; - i32 total_visual_count; - u32_Ptr_Table id_to_ptr_table; }; struct Managed_Arena_Header{ @@ -91,32 +60,24 @@ struct Managed_Arena_Header_List{ //////////////////////////////// -struct Dynamic_Variable_Slot{ - Dynamic_Variable_Slot *next; - Dynamic_Variable_Slot *prev; - String_Const_u8 name; - u64 default_value; - i32 location; -}; - -struct Dynamic_Variable_Layout{ - Dynamic_Variable_Slot sentinel; - i32 location_counter; +struct Managed_ID_Set{ + Arena arena; + Table_Data_u64 name_to_id_table; + Managed_ID id_counter; }; struct Dynamic_Variable_Block{ - u64 *val_array; - i32 count; - i32 max; + Arena arena; + Table_u64_Data id_to_data_table; }; //////////////////////////////// struct Dynamic_Workspace{ Dynamic_Variable_Block var_block; - Memory_Bank mem_bank; - Marker_Visual_Allocator visual_allocator; - u32_Ptr_Table object_id_to_object_ptr; + Heap heap; + Base_Allocator heap_wrapper; + Table_u64_u64 object_id_to_object_ptr; u32 object_id_counter; u32 visual_id_counter; u32 scope_id; @@ -169,14 +130,6 @@ struct Lifetime_Key{ global_const u64 LifetimeKeyHash_Empty = 0&(~bit_63); global_const u64 LifetimeKeyHash_Deleted = max_u64&(~bit_63); -struct Lifetime_Key_Table{ - void *mem_ptr; - u64 *hashes; - Lifetime_Key **keys; - u32 count; - u32 max; -}; - struct Lifetime_Key_Ref_Node_List{ Lifetime_Key_Ref_Node *first; Lifetime_Key_Ref_Node *last; @@ -196,12 +149,13 @@ struct Lifetime_Key_List{ }; struct Lifetime_Allocator{ + Base_Allocator *allocator; Lifetime_Key_Ref_Node_List free_key_references; Lifetime_Object_List free_objects; Lifetime_Key_List free_keys; - Lifetime_Key_Table key_table; - Ptr_Table key_check_table; - u32_Ptr_Table scope_id_to_scope_ptr_table; + Table_Data_u64 key_table; + Table_u64_u64 key_check_table; + Table_u64_u64 scope_id_to_scope_ptr_table; u32 scope_id_counter; }; diff --git a/4ed_edit.cpp b/4ed_edit.cpp index 4dfe52e4..709a15bb 100644 --- a/4ed_edit.cpp +++ b/4ed_edit.cpp @@ -10,7 +10,7 @@ // TOP internal void -edit_pre_state_change(Models *models, Heap *heap, Editing_File *file){ +edit_pre_state_change(Models *models, Editing_File *file){ System_Functions *system = models->system; file_add_dirty_flag(file, DirtyState_UnsavedChanges); file_unmark_edit_finished(&models->working_set, file); @@ -18,7 +18,8 @@ edit_pre_state_change(Models *models, Heap *heap, Editing_File *file){ internal void edit_fix_markers__write_workspace_markers(Dynamic_Workspace *workspace, Buffer_ID buffer_id, - Cursor_With_Index *cursors, Cursor_With_Index *r_cursors, i32 *cursor_count, i32 *r_cursor_count){ + Cursor_With_Index *cursors, Cursor_With_Index *r_cursors, + i32 *cursor_count, i32 *r_cursor_count){ for (Managed_Buffer_Markers_Header *node = workspace->buffer_markers_list.first; node != 0; node = node->next){ @@ -189,19 +190,18 @@ edit_single(Models *models, Editing_File *file, Interval_i64 range, String_Const Assert(edit.range.first <= edit.range.one_past_last); Assert(edit.range.one_past_last <= buffer_size(buffer)); - Heap *heap = &models->mem.heap; Arena *scratch = &models->mem.arena; // NOTE(allen): history update if (!behaviors.do_not_post_to_history){ // TODO(allen): if the edit number counter is not updated, maybe auto-merge edits? Wouldn't that just work? history_dump_records_after_index(&file->state.history, file->state.current_record_index); - history_record_edit(heap, &models->global_history, &file->state.history, buffer, edit); + history_record_edit(&models->global_history, &file->state.history, buffer, edit); file->state.current_record_index = history_get_record_count(&file->state.history); } // NOTE(allen): fixing stuff beforewards???? - edit_pre_state_change(models, heap, file); + edit_pre_state_change(models, file); // NOTE(allen): edit range hook if (models->hook_file_edit_range != 0){ @@ -221,13 +221,9 @@ edit_single(Models *models, Editing_File *file, Interval_i64 range, String_Const i64 new_line_count = buffer_count_newlines(scratch, buffer, edit.range.first, edit.range.first + edit.text.size); i64 line_shift = new_line_count - replaced_line_count; + file_clear_layout_cache(file); buffer_remeasure_starts(scratch, buffer, Ii64(line_start, line_end + 1), line_shift, shift_amount); - // NOTE(allen): token fixing - if (file->settings.tokens_exist){ - file_relex(models->system, models, file, edit.range.first, edit.range.one_past_last, shift_amount); - } - // NOTE(allen): cursor fixing edit_fix_markers(models, file, edit); @@ -240,10 +236,9 @@ file_end_file(Models *models, Editing_File *file){ if (models->hook_end_file != 0){ models->hook_end_file(&models->app_links, file->id); } - Heap *heap = &models->mem.heap; Lifetime_Allocator *lifetime_allocator = &models->lifetime_allocator; - lifetime_free_object(heap, lifetime_allocator, file->lifetime_object); - file->lifetime_object = lifetime_alloc_object(heap, lifetime_allocator, DynamicWorkspace_Buffer, file); + lifetime_free_object(lifetime_allocator, file->lifetime_object); + file->lifetime_object = lifetime_alloc_object(lifetime_allocator, DynamicWorkspace_Buffer, file); } internal void @@ -375,7 +370,7 @@ edit_merge_history_range(Models *models, Editing_File *file, History_Record_Inde }break; } } - history_merge_records(&models->mem.arena, &models->mem.heap, history, first_index, last_index); + history_merge_records(&models->mem.arena, history, first_index, last_index); if (current_index >= last_index){ current_index -= (last_index - first_index); } @@ -490,10 +485,10 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags) file = working_set_allocate_file(working_set, &models->lifetime_allocator); if (file != 0){ if (has_canon_name){ - file_bind_file_name(system, heap, working_set, file, string_from_file_name(&canon)); + file_bind_file_name(system, working_set, file, string_from_file_name(&canon)); } String_Const_u8 front = string_front_of_path(file_name); - buffer_bind_name(models, heap, scratch, working_set, file, front); + buffer_bind_name(models, scratch, working_set, file, front); File_Attributes attributes = {}; file_create_from_string(models, file, SCu8(""), attributes); result = file; @@ -515,9 +510,9 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags) system->load_close(handle); file = working_set_allocate_file(working_set, &models->lifetime_allocator); if (file != 0){ - file_bind_file_name(system, heap, working_set, file, string_from_file_name(&canon)); + file_bind_file_name(system, working_set, file, string_from_file_name(&canon)); String_Const_u8 front = string_front_of_path(file_name); - buffer_bind_name(models, heap, scratch, working_set, file, front); + buffer_bind_name(models, scratch, working_set, file, front); file_create_from_string(models, file, SCu8(buffer, (i32)attributes.size), attributes); result = file; } diff --git a/4ed_file.cpp b/4ed_file.cpp index 5819eb35..89e71c12 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -213,8 +213,6 @@ file_compute_cursor(Editing_File *file, Buffer_Seek seek){ internal void file_create_from_string(Models *models, Editing_File *file, String_Const_u8 val, File_Attributes attributes){ System_Functions *system = models->system; - // TODO(allen): completely eliminate the heap, then clean up the implementation or remove it too! - Heap *heap = &models->mem.heap; Arena *scratch = &models->mem.arena; Application_Links *app_links = &models->app_links; Base_Allocator *allocator = models->base_allocator; @@ -232,27 +230,10 @@ file_create_from_string(Models *models, Editing_File *file, String_Const_u8 val, buffer_measure_starts(scratch, &file->state.buffer); - file->lifetime_object = lifetime_alloc_object(heap, &models->lifetime_allocator, DynamicWorkspace_Buffer, file); + file->lifetime_object = lifetime_alloc_object(&models->lifetime_allocator, DynamicWorkspace_Buffer, file); history_init(&models->app_links, &file->state.history); - // TODO(allen): do(cleanup the create and settings dance) - // Right now we have this thing where we call hook_open_file, which may or may not - // trigger a lex job or serial lex, or might just flag the buffer to say it wants - // tokens. Then we check if we need to lex still and do it here too. Better would - // be to make sure it always happens in one way. - Open_File_Hook_Function *hook_open_file = models->hook_open_file; - if (hook_open_file != 0){ - hook_open_file(app_links, file->id); - } - - if (file->settings.tokens_exist){ - if (file->state.token_array.tokens == 0){ - file_first_lex(system, models, file); - } - } - else{ - file_mark_edit_finished(&models->working_set, file); - } + file_mark_edit_finished(&models->working_set, file); file->state.cached_layouts_arena = make_arena(allocator); file->state.line_layout_table = make_table_Data_u64(allocator, 500); @@ -268,15 +249,18 @@ file_create_from_string(Models *models, Editing_File *file, String_Const_u8 val, attributes.last_write_time, string_expand(name)); end_temp(temp); } + + //////////////////////////////// + + Buffer_Hook_Function *hook_open_file = models->hook_open_file; + if (hook_open_file != 0){ + hook_open_file(app_links, file->id); + } } internal void -file_free(System_Functions *system, Heap *heap, Lifetime_Allocator *lifetime_allocator, Working_Set *working_set, Editing_File *file){ - if (file->state.token_array.tokens){ - heap_free(heap, file->state.token_array.tokens); - } - - lifetime_free_object(heap, lifetime_allocator, file->lifetime_object); +file_free(System_Functions *system, Lifetime_Allocator *lifetime_allocator, Working_Set *working_set, Editing_File *file){ + lifetime_free_object(lifetime_allocator, file->lifetime_object); Gap_Buffer *buffer = &file->state.buffer; if (buffer->data){ @@ -284,7 +268,7 @@ file_free(System_Functions *system, Heap *heap, Lifetime_Allocator *lifetime_all base_free(buffer->allocator, buffer->line_starts); } - history_free(heap, &file->state.history); + history_free(&file->state.history); linalloc_clear(&file->state.cached_layouts_arena); table_free(&file->state.line_layout_table); @@ -299,11 +283,6 @@ file_get_current_record_index(Editing_File *file){ return(file->state.current_record_index); } -internal b32 -file_tokens_are_ready(Editing_File *file){ - return(file->state.token_array.tokens != 0); -} - internal Managed_Scope file_get_managed_scope(Editing_File *file){ Managed_Scope scope = 0; diff --git a/4ed_file.h b/4ed_file.h index 7d494fe7..2b2e976d 100644 --- a/4ed_file.h +++ b/4ed_file.h @@ -35,11 +35,8 @@ struct Text_Effect{ struct Editing_File_Settings{ i32 base_map_id; - Parse_Context_ID parse_context_id; b32 dos_write_mode; Face_ID face_id; - b8 tokens_exist; - b8 tokens_without_strings; b8 is_initialized; b8 unimportant; b8 read_only; @@ -59,10 +56,6 @@ struct Editing_File_State{ History history; i32 current_record_index; - // TODO(allen): eliminate this too - Cpp_Token_Array token_array; - b32 in_edit_handler; - Text_Effect paste_effect; Dirty_State dirty; diff --git a/4ed_file_lex.cpp b/4ed_file_lex.cpp deleted file mode 100644 index 0a7ca8f3..00000000 --- a/4ed_file_lex.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 19.08.2018 - * - * Ways of calling lexer for the text in Editing_File - * - */ - -// TOP - -internal void -file_kill_tokens(System_Functions *system, Heap *heap, Editing_File *file){ - file->settings.tokens_exist = false; - if (file->state.token_array.tokens != 0){ - heap_free(heap, file->state.token_array.tokens); - } - block_zero_struct(&file->state.token_array); -} - -internal void -file_first_lex_serial(System_Functions *system, Models *models, Editing_File *file){ - Mem_Options *mem = &models->mem; - Arena *scratch = &mem->arena; - Heap *heap = &mem->heap; - file->settings.tokens_exist = true; - - if (file->is_loading == 0){ - Assert(file->state.token_array.tokens == 0); - - Temp_Memory temp = begin_temp(scratch); - - Parse_Context parse_context = parse_context_get(scratch, &models->parse_context_memory, file->settings.parse_context_id); - Assert(parse_context.valid); - - Gap_Buffer *buffer = &file->state.buffer; - i64 text_size = buffer_size(buffer); - - // TODO(allen): REWRITE REWRITE REWRITE - Cpp_Token_Array new_tokens = {}; - new_tokens.max_count = Million(1); - new_tokens.count = 0; - new_tokens.tokens = push_array(scratch, Cpp_Token, new_tokens.max_count); - - b32 still_lexing = true; - - Cpp_Lex_Data lex = cpp_lex_data_init(file->settings.tokens_without_strings, parse_context.kw_table, parse_context.pp_table); - - List_String_Const_u8 chunks = buffer_get_chunks(scratch, buffer); - u8 null_terminator = 0; - string_list_push(scratch, &chunks, SCu8(&null_terminator, 1)); - - Cpp_Token_Array new_array = {}; - - for (Node_String_Const_u8 *node = chunks.first; - node != 0;){ - u8 *chunk = node->string.str; - umem chunk_size = node->string.size; - - i32 result = cpp_lex_step(&lex, (char*)chunk, (i32)chunk_size, (i32)text_size, &new_tokens, NO_OUT_LIMIT); - - switch (result){ - case LexResult_NeedChunk: - { - node = node->next; - }break; - - case LexResult_Finished: - case LexResult_NeedTokenMemory: - { - u32 new_max = round_up_u32(new_array.count + new_tokens.count + 1, KB(1)); - if (new_array.tokens == 0){ - new_array.tokens = heap_array(heap, Cpp_Token, new_max); - } - else{ - u32 old_count = new_array.count; - Cpp_Token *new_token_mem = heap_array(heap, Cpp_Token, new_max); - memcpy(new_token_mem, new_array.tokens, sizeof(*new_token_mem)*old_count); - heap_free(heap, new_array.tokens); - new_array.tokens = new_token_mem; - } - new_array.max_count = new_max; - - Assert(new_array.count + new_tokens.count <= new_array.max_count); - memcpy(new_array.tokens + new_array.count, new_tokens.tokens, new_tokens.count*sizeof(Cpp_Token)); - new_array.count += new_tokens.count; - new_tokens.count = 0; - - if (result == LexResult_Finished){ - still_lexing = false; - } - }break; - - case LexResult_HitTokenLimit: InvalidPath; - } - - if (!still_lexing){ - break; - } - } - - Cpp_Token_Array *token_array = &file->state.token_array; - token_array->count = new_array.count; - token_array->max_count = new_array.max_count; - if (token_array->tokens != 0){ - heap_free(heap, token_array->tokens); - } - token_array->tokens = new_array.tokens; - - new_array.tokens = 0; - new_array.count = 0; - new_array.max_count = 0; - - end_temp(temp); - - file_mark_edit_finished(&models->working_set, file); - } -} - -internal b32 -file_relex_serial(System_Functions *system, Models *models, Editing_File *file, i64 start_i, i64 end_i, i64 shift_amount){ - Mem_Options *mem = &models->mem; - Arena *scratch = &mem->arena; - Heap *heap = &mem->heap; - - if (file->state.token_array.tokens == 0){ - file_first_lex_serial(system, models, file); - } - else{ - Gap_Buffer *buffer = &file->state.buffer; - Cpp_Token_Array *array = &file->state.token_array; - - Temp_Memory temp = begin_temp(scratch); - Parse_Context parse_context = parse_context_get(scratch, &models->parse_context_memory, file->settings.parse_context_id); - Assert(parse_context.valid); - - Cpp_Token_Array relex_array = {}; - relex_array.count = 0; - relex_array.max_count = Million(1); - relex_array.tokens = push_array(scratch, Cpp_Token, relex_array.max_count); - - i64 size = buffer_size(buffer); - - Cpp_Relex_Data state = cpp_relex_init(array, (i32)start_i, (i32)end_i, (i32)shift_amount, file->settings.tokens_without_strings, parse_context.kw_table, parse_context.pp_table); - - List_String_Const_u8 chunks = buffer_get_chunks(scratch, buffer); - u8 null_terminator = 0; - string_list_push(scratch, &chunks, SCu8(&null_terminator, 1)); - Node_String_Const_u8 *node = chunks.first; - - i32 chunk_index = 0; - u8 *chunk = 0; - umem chunk_size = 0; - if (node != 0){ - chunk = node->string.str; - chunk_size = node->string.size; - } - for (;!cpp_relex_is_start_chunk(&state, (char*)chunk, (i32)chunk_size);){ - node = node->next; - Assert(node != 0); - chunk = node->string.str; - chunk_size = node->string.size; - } - for(;;){ - Cpp_Lex_Result lex_result = cpp_relex_step(&state, (char*)chunk, (i32)chunk_size, (i32)size, array, &relex_array); - - switch (lex_result){ - case LexResult_NeedChunk: - { - node = node->next; - Assert(node != 0); - chunk = node->string.str; - chunk_size = node->string.size; - }break; - - case LexResult_NeedTokenMemory: InvalidPath; - - case LexResult_Finished: goto doublebreak; - } - } - doublebreak:; - - i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array); - if (new_count > array->max_count){ - i32 new_max = round_up_i32(new_count, KB(1)); - Cpp_Token *new_tokens = heap_array(heap, Cpp_Token, new_max); - memcpy(new_tokens, array->tokens, array->count*sizeof(Cpp_Token)); - heap_free(heap, array->tokens); - array->tokens = new_tokens; - array->max_count = new_max; - } - - cpp_relex_complete(&state, array, &relex_array); - - end_temp(temp); - } - - return(true); -} - -internal void -file_first_lex(System_Functions *system, Models *models, Editing_File *file){ - file_first_lex_serial(system, models, file); -} - -internal void -file_relex(System_Functions *system, Models *models, Editing_File *file, i64 start, i64 end, i64 shift_amount){ - file_relex_serial(system, models, file, start, end, shift_amount); -} - -// BOTTOM - diff --git a/4ed_history.cpp b/4ed_history.cpp index 7f2426d0..a5eba5e8 100644 --- a/4ed_history.cpp +++ b/4ed_history.cpp @@ -25,13 +25,14 @@ history__to_node(Node *sentinel, i32 index){ } internal void -history__push_back_record_ptr(Heap *heap, Record_Ptr_Lookup_Table *lookup, Record *record){ +history__push_back_record_ptr(Base_Allocator *allocator, Record_Ptr_Lookup_Table *lookup, Record *record){ if (lookup->records == 0 || lookup->count == lookup->max){ i32 new_max = clamp_bot(1024, lookup->max*2); - Record **new_records = (Record**)heap_allocate(heap, sizeof(Record*)*new_max); + Data new_memory = base_allocate(allocator, sizeof(Record*)*new_max); + Record **new_records = (Record**)new_memory.data; block_copy(new_records, lookup->records, sizeof(*new_records)*lookup->count); if (lookup->records != 0){ - heap_free(heap, lookup->records); + base_free(allocator, lookup->records); } lookup->records = new_records; lookup->max = new_max; @@ -77,12 +78,13 @@ history__to_node(History *history, i32 index){ //////////////////////////////// internal Record* -history__allocate_record(Heap *heap, History *history){ +history__allocate_record(History *history){ Node *sentinel = &history->free_records; Node *new_node = sentinel->next; if (new_node == sentinel){ i32 new_record_count = 1024; - void *memory = memory_bank_allocate(heap, &history->bank, sizeof(Record)*new_record_count); + Data new_memory = base_allocate(&history->heap_wrapper, sizeof(Record)*new_record_count); + void *memory = new_memory.data; Record *new_record = (Record*)memory; sentinel->next = &new_record->node; @@ -130,7 +132,8 @@ internal void history_init(Application_Links *app, History *history){ history->activated = true; history->arena = make_arena_app_links(app, KB(32)); - memory_bank_init(&history->bank); + heap_init(&history->heap, history->arena.base_allocator); + history->heap_wrapper = base_allocator_on_heap(&history->heap); dll_init_sentinel(&history->free_records); dll_init_sentinel(&history->records); history->record_count = 0; @@ -143,10 +146,10 @@ history_is_activated(History *history){ } internal void -history_free(Heap *heap, History *history){ +history_free(History *history){ if (history->activated){ linalloc_clear(&history->arena); - memory_bank_free_all(heap, &history->bank); + heap_free_all(&history->heap); block_zero_struct(history); } } @@ -196,11 +199,11 @@ history_get_dummy_record(History *history){ } internal void -history__stash_record(Heap *heap, History *history, Record *new_record){ +history__stash_record(History *history, Record *new_record){ Assert(history->record_lookup.count == history->record_count); dll_insert_back(&history->records, &new_record->node); history->record_count += 1; - history__push_back_record_ptr(heap, &history->record_lookup, new_record); + history__push_back_record_ptr(&history->heap_wrapper, &history->record_lookup, new_record); Assert(history->record_lookup.count == history->record_count); } @@ -238,12 +241,12 @@ history__free_nodes(History *history, i32 first_index, Node *first_node, Node *l } internal void -history_record_edit(Heap *heap, Global_History *global_history, History *history, Gap_Buffer *buffer, Edit edit){ +history_record_edit(Global_History *global_history, History *history, Gap_Buffer *buffer, Edit edit){ if (history->activated){ Assert(history->record_lookup.count == history->record_count); - Record *new_record = history__allocate_record(heap, history); - history__stash_record(heap, history, new_record); + Record *new_record = history__allocate_record(history); + history__stash_record(history, new_record); new_record->restore_point = begin_temp(&history->arena); new_record->edit_number = global_history_get_edit_number(global_history); @@ -353,7 +356,7 @@ history__optimize_group(Arena *scratch, History *history, Record *record){ } internal void -history_merge_records(Arena *scratch, Heap *heap, History *history, i32 first_index, i32 last_index){ +history_merge_records(Arena *scratch, History *history, i32 first_index, i32 last_index){ if (history->activated){ Assert(history->record_lookup.count == history->record_count); Assert(first_index < last_index); @@ -362,7 +365,7 @@ history_merge_records(Arena *scratch, Heap *heap, History *history, i32 first_in Assert(first_node != &history->records && first_node != 0); Assert(last_node != &history->records && last_node != 0); - Record *new_record = history__allocate_record(heap, history); + Record *new_record = history__allocate_record(history); // NOTE(allen): here we remove (last_index - first_index + 1) nodes, and insert 1 node // which simplifies to this: diff --git a/4ed_history.h b/4ed_history.h index bce76122..38f91765 100644 --- a/4ed_history.h +++ b/4ed_history.h @@ -45,7 +45,8 @@ struct Record_Ptr_Lookup_Table{ struct History{ b32 activated; Arena arena; - Memory_Bank bank; + Heap heap; + Base_Allocator heap_wrapper; Node free_records; Node records; i32 record_count; diff --git a/4ed_memory_bank.cpp b/4ed_memory_bank.cpp deleted file mode 100644 index 93fdb374..00000000 --- a/4ed_memory_bank.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* -* Mr. 4th Dimention - Allen Webster -* -* 07.02.2019 -* -* Memory bank wrapper for heap -* -*/ - -// TOP - -internal void -memory_bank_init(Memory_Bank *mem_bank){ - heap_init(&mem_bank->heap); - mem_bank->first = 0; - mem_bank->last = 0; - mem_bank->total_memory_size = 0; -} - -internal void* -memory_bank_allocate(Heap *heap, Memory_Bank *mem_bank, i32 size){ - void *ptr = heap_allocate(&mem_bank->heap, size); - if (ptr == 0){ - i32 alloc_size = clamp_bot(4096, size*4 + sizeof(Memory_Header)); - void *new_block = heap_allocate(heap, alloc_size); - if (new_block != 0){ - Memory_Header *header = (Memory_Header*)new_block; - sll_queue_push(mem_bank->first, mem_bank->last, header); - mem_bank->total_memory_size += alloc_size; - heap_extend(&mem_bank->heap, header + 1, alloc_size - sizeof(*header)); - ptr = heap_allocate(&mem_bank->heap, size); - } - } - return(ptr); -} - -internal void -memory_bank_free(Memory_Bank *mem_bank, void *ptr){ - heap_free(&mem_bank->heap, ptr); -} - -internal void -memory_bank_free_all(Heap *heap, Memory_Bank *mem_bank){ - for (Memory_Header *header = mem_bank->first, *next = 0; - header != 0; - header = next){ - next = header->next; - heap_free(heap, header); - } - mem_bank->total_memory_size = 0; -} - -// BOTTOM - diff --git a/4ed_memory_bank.h b/4ed_memory_bank.h deleted file mode 100644 index 728e1d76..00000000 --- a/4ed_memory_bank.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -* Mr. 4th Dimention - Allen Webster -* -* 07.02.2019 -* -* Memory bank wrapper for heap -* -*/ - -// TOP - -#if !defined(FRED_MEMORY_BANK_H) -#define FRED_MEMORY_BANK_H - -struct Memory_Header{ - Memory_Header *next; -}; - -struct Memory_Bank{ - Heap heap; - Memory_Header *first; - Memory_Header *last; - umem total_memory_size; -}; - -#endif - -// BOTTOM - diff --git a/4ed_parse_context.cpp b/4ed_parse_context.cpp deleted file mode 100644 index 96f8581e..00000000 --- a/4ed_parse_context.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 19.05.2017 - * - * Parse contexts allocation and locking - * - */ - -// TOP - -internal void -parse_context_init_memory(Parse_Context_Memory *parse_mem, void *mem, umem memsize){ - parse_mem->free_list = 0; - - parse_mem->parse_context_array = (Stored_Parse_Context_Slot*)mem; - parse_mem->parse_context_counter = 0; - parse_mem->parse_context_max = (u32)(memsize/sizeof(*parse_mem->parse_context_array)); -} - -internal Parse_Context_ID -parse_context_valid_id(Parse_Context_Memory *parse_mem, Parse_Context_ID id){ - Parse_Context_ID valid_id = 0; - if (id > parse_mem->parse_context_max && id < parse_mem->parse_context_max*2){ - valid_id = id; - } - return(valid_id); -} - -internal Parse_Context_ID -parse_context_add(Parse_Context_Memory *parse_mem, Heap *heap, Parser_String_And_Type *kw_sats, u32 kw_count, Parser_String_And_Type *pp_sats, u32 pp_count){ - Stored_Parse_Context_Slot *slot = 0; - if (parse_mem->free_list != 0){ - slot = parse_mem->free_list; - sll_stack_pop(parse_mem->free_list); - } - else if (parse_mem->parse_context_counter < parse_mem->parse_context_max){ - slot = &parse_mem->parse_context_array[parse_mem->parse_context_counter++]; - } - - u32 result = 0; - if (slot != 0){ - u32 stride = sizeof(*kw_sats); - umem kw_memsize = cpp_get_table_memory_size_string_lengths(&kw_sats->length, stride, kw_count); - umem pp_memsize = cpp_get_table_memory_size_string_lengths(&pp_sats->length, stride, pp_count); - - umem memsize = kw_memsize + pp_memsize + sizeof(Stored_Parse_Context); - void *mem = heap_allocate(heap, (i32)memsize); - - Stored_Parse_Context *parse_context = (Stored_Parse_Context*)mem; - u8 *kw_mem = (u8*)(parse_context+1); - u8 *pp_mem = kw_mem + kw_memsize; - - Cpp_Keyword_Table kw_table = cpp_make_table(&kw_sats->str, stride, &kw_sats->length, stride, &kw_sats->type, stride, kw_count, kw_mem, kw_memsize); - - Cpp_Keyword_Table pp_table = cpp_make_table(&pp_sats->str, stride, &pp_sats->length, stride, &pp_sats->type, stride, pp_count, pp_mem, pp_memsize); - - parse_context->memsize = memsize; - parse_context->kw_keywords = kw_table.keywords; - parse_context->pp_keywords = pp_table.keywords; - parse_context->kw_max = kw_table.max; - parse_context->pp_max = pp_table.max; - slot->context = parse_context; - slot->freed = false; - - result = (u32)(slot - parse_mem->parse_context_array) + parse_mem->parse_context_max; - } - - return(result); -} - -internal u32 -parse_context_add_default(Parse_Context_Memory *parse_mem, Heap *heap){ - Stored_Parse_Context_Slot *slot = 0; - if (parse_mem->free_list != 0){ - slot = parse_mem->free_list; - sll_stack_pop(parse_mem->free_list); - } - else if (parse_mem->parse_context_counter < parse_mem->parse_context_max){ - slot = &parse_mem->parse_context_array[parse_mem->parse_context_counter++]; - } - - u32 result = 0; - if (slot != 0){ - umem kw_memsize = cpp_get_table_memory_size_default(CPP_TABLE_KEYWORDS); - umem pp_memsize = cpp_get_table_memory_size_default(CPP_TABLE_PREPROCESSOR_DIRECTIVES); - - umem memsize = kw_memsize + pp_memsize + sizeof(Stored_Parse_Context); - void *mem = heap_allocate(heap, (i32)(memsize)); - - Stored_Parse_Context *parse_context = (Stored_Parse_Context*)mem; - u8 *kw_mem = (u8*)(parse_context+1); - u8 *pp_mem = kw_mem + kw_memsize; - - Cpp_Keyword_Table kw_table = cpp_make_table_default(CPP_TABLE_KEYWORDS, kw_mem, kw_memsize); - Cpp_Keyword_Table pp_table = cpp_make_table_default(CPP_TABLE_PREPROCESSOR_DIRECTIVES, pp_mem, pp_memsize); - - parse_context->memsize = memsize; - parse_context->kw_keywords = kw_table.keywords; - parse_context->pp_keywords = pp_table.keywords; - parse_context->kw_max = kw_table.max; - parse_context->pp_max = pp_table.max; - slot->context = parse_context; - slot->freed = false; - - result = (u32)(slot - parse_mem->parse_context_array) + parse_mem->parse_context_max; - } - - return(result); -} - -internal Stored_Parse_Context_Slot* -parse_context_get_slot(Parse_Context_Memory *parse_mem, Parse_Context_ID id){ - Stored_Parse_Context_Slot *slot = 0; - if (id == 0){ - // do nothing - } - else{ - id -= parse_mem->parse_context_max; - } - if (id < parse_mem->parse_context_counter){ - slot = &parse_mem->parse_context_array[id]; - if (slot->freed){ - slot = 0; - } - } - return(slot); -} - -internal Parse_Context -parse_context_get(Parse_Context_Memory *parse_mem, Parse_Context_ID id, void *mem, umem memsize){ - Stored_Parse_Context_Slot *slot = parse_context_get_slot(parse_mem, id); - Parse_Context result = {}; - if (slot != 0){ - Stored_Parse_Context *context = slot->context; - if (context->memsize < memsize){ - u8 *base_ptr = (u8*)context; - u8 *kw_keywords = (u8*)mem + (((u8*)context->kw_keywords) - base_ptr); - u8 *pp_keywords = (u8*)mem + (((u8*)context->pp_keywords) - base_ptr); - result.valid = true; - result.kw_table.keywords = (u64*)kw_keywords; - result.pp_table.keywords = (u64*)pp_keywords; - result.kw_table.max = context->kw_max; - result.pp_table.max = context->pp_max; - result.memory_size = context->memsize; - memcpy(mem, context, context->memsize); - } - } - return(result); -} - -internal Parse_Context -parse_context_get(Arena *arena, Parse_Context_Memory *parse_mem, Parse_Context_ID id){ - Stored_Parse_Context_Slot *slot = parse_context_get_slot(parse_mem, id); - Parse_Context result = {}; - if (slot != 0){ - Stored_Parse_Context *context = slot->context; - umem memsize = context->memsize + 1; - u8 *mem = push_array(arena, u8, memsize); - result = parse_context_get(parse_mem, id, mem, memsize); - } - return(result); -} - -internal void -parse_context_rebase(Parse_Context *parse_mem, void *old_base, void *new_base){ - u8 *old_base_ptr = (u8*)old_base; - u8 *new_base_ptr = (u8*)new_base; - - u8 *ptr = (u8*)parse_mem->kw_table.keywords; - parse_mem->kw_table.keywords = (u64*)(ptr + (new_base_ptr - old_base_ptr)); - - ptr = (u8*)parse_mem->pp_table.keywords; - parse_mem->pp_table.keywords = (u64*)(ptr + (new_base_ptr - old_base_ptr)); -} - -// BOTTOM - diff --git a/4ed_ptr_check.cpp b/4ed_ptr_check.cpp deleted file mode 100644 index e9eed30d..00000000 --- a/4ed_ptr_check.cpp +++ /dev/null @@ -1,361 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 26.08.2018 - * - * Pointer check table - * - */ - -// TOP - -internal Ptr_Table -make_Ptr_table(void *mem, umem size){ - Ptr_Table table = {}; - i32 max = (i32)(size/8); - if (max > 0){ - table.mem = mem; - u8 *cursor = (u8*)mem; - table.hashes = (u64*)cursor; - cursor += 8*max; - table.count = 0; - table.max = max; - block_fill_ones(table.hashes, sizeof(*table.hashes)*max); - } - return(table); -} - -internal i32 -max_to_memsize_Ptr_table(i32 max){ - return(max*8); -} - -internal b32 -at_max_Ptr_table(Ptr_Table *table){ - if (table->max > 0 && (table->count + 1)*8 <= table->max*7){ - return(false); - } - return(true); -} - -internal b32 -insert_Ptr_table(Ptr_Table *table, void**key){ - i32 max = table->max; - if (max > 0){ - i32 count = table->count; - if ((count + 1)*8 <= max*7){ - u64 hash = 0; - block_copy(&hash, key, 8); - if (hash >= 18446744073709551614ULL){ hash += 2; } - i32 first_index = hash%max; - i32 index = first_index; - u64 *hashes = table->hashes; - for (;;){ - if (hashes[index] == 18446744073709551615ULL){ - table->dirty_slot_count += 1; - } - if (hashes[index] == 18446744073709551615ULL || hashes[index] == 18446744073709551614ULL){ - hashes[index] = hash; - table->count += 1; - return(true); - } - if (hashes[index] == hash) return(false); - index = (index + 1)%max; - if (index == first_index) return(false); - } - } - } - return(false); -} - -internal b32 -lookup_Ptr_table(Ptr_Table *table, void**key){ - i32 max = table->max; - if (max > 0){ - u64 hash = 0; - block_copy(&hash, key, 8); - if (hash >= 18446744073709551614ULL){ hash += 2; } - i32 first_index = hash%max; - i32 index = first_index; - u64 *hashes = table->hashes; - for (;;){ - if (hashes[index] == 18446744073709551615ULL) break; - if (hashes[index] == hash){ - return(true); - } - index = (index + 1)%max; - if (index == first_index) break; - } - } - return(false); -} - -internal b32 -erase_Ptr_table(Ptr_Table *table, void**key){ - i32 max = table->max; - if (max > 0 && table->count > 0){ - u64 hash = 0; - block_copy(&hash, key, 8); - if (hash >= 18446744073709551614ULL){ hash += 2; } - i32 first_index = hash%max; - i32 index = first_index; - u64 *hashes = table->hashes; - for (;;){ - if (hashes[index] == 18446744073709551615ULL) break; - if (hashes[index] == hash){ - hashes[index] = 18446744073709551614ULL; - table->count -= 1; - return(true); - } - index = (index + 1)%max; - if (index == first_index) break; - } - } - return(false); -} - -internal b32 -move_Ptr_table(Ptr_Table *dst_table, Ptr_Table *src_table){ - if ((src_table->count + dst_table->count)*8 <= dst_table->max*7){ - i32 max = src_table->max; - u64 *hashes = src_table->hashes; - for (i32 index = 0; index < max; index += 1){ - if (hashes[index] != 18446744073709551615ULL && hashes[index] != 18446744073709551614ULL){ - void* key_; - void**key = &key_; - block_copy(key, &hashes[index], 8); - insert_Ptr_table(dst_table, key); - } - } - return(true); - } - return(false); -} - -internal b32 -insert_Ptr_table(Ptr_Table *table, void* key){ - return(insert_Ptr_table(table, &key)); -} - -internal b32 -lookup_Ptr_table(Ptr_Table *table, void* key){ - return(lookup_Ptr_table(table, &key)); -} - -internal b32 -erase_Ptr_table(Ptr_Table *table, void* key){ - return(erase_Ptr_table(table, &key)); -} - -//////////////////////////////// - -internal void -insert_Ptr_table(Heap *heap, Ptr_Table *table, void* key){ - if (at_max_Ptr_table(table)){ - i32 new_max = (table->max + 1)*2; - i32 new_mem_size = max_to_memsize_Ptr_table(new_max); - void *new_mem = heap_allocate(heap, new_mem_size); - Ptr_Table new_table = make_Ptr_table(new_mem, new_mem_size); - if (table->mem != 0){ - b32 result = move_Ptr_table(&new_table, table); - Assert(result); - heap_free(heap, table->mem); - } - *table = new_table; - } - b32 result = insert_Ptr_table(table, &key); - Assert(result); -} - -//////////////////////////////// - -internal u32_Ptr_Table -make_u32_Ptr_table(void *mem, umem size){ - u32_Ptr_Table table = {}; - i32 max = (i32)(size/16); - if (max > 0){ - table.mem = mem; - u8 *cursor = (u8*)mem; - table.hashes = (u64*)cursor; - cursor += 8*max; - table.vals = (void**)cursor; - table.count = 0; - table.max = max; - block_fill_ones(table.hashes, sizeof(*table.hashes)*max); - } - return(table); -} - -internal i32 -max_to_memsize_u32_Ptr_table(i32 max){ - return(max*16); -} - -internal b32 -at_max_u32_Ptr_table(u32_Ptr_Table *table){ - if (table->max > 0 && (table->count + 1)*8 <= table->max*7){ - return(false); - } - return(true); -} - -internal b32 -insert_u32_Ptr_table(u32_Ptr_Table *table, u32*key, void**val){ - i32 max = table->max; - if (max > 0){ - i32 count = table->count; - if ((count + 1)*8 <= max*7){ - u64 hash = 0; - block_copy(&hash, key, 4); - if (hash >= 18446744073709551614ULL){ hash += 2; } - i32 first_index = hash%max; - i32 index = first_index; - u64 *hashes = table->hashes; - for (;;){ - if (hashes[index] == 18446744073709551615ULL){ - table->dirty_slot_count += 1; - } - if (hashes[index] == 18446744073709551615ULL || hashes[index] == 18446744073709551614ULL){ - hashes[index] = hash; - table->vals[index] = *val; - table->count += 1; - return(true); - } - if (hashes[index] == hash) return(false); - index = (index + 1)%max; - if (index == first_index) return(false); - } - } - } - return(false); -} - -internal u32_Ptr_Lookup_Result -lookup_u32_Ptr_table(u32_Ptr_Table *table, u32*key){ - u32_Ptr_Lookup_Result result = {}; - i32 max = table->max; - if (max > 0){ - u64 hash = 0; - block_copy(&hash, key, 4); - if (hash >= 18446744073709551614ULL){ hash += 2; } - i32 first_index = hash%max; - i32 index = first_index; - u64 *hashes = table->hashes; - for (;;){ - if (hashes[index] == 18446744073709551615ULL) break; - if (hashes[index] == hash){ - result.success = true; - result.val = &table->vals[index]; - return(result); - } - index = (index + 1)%max; - if (index == first_index) break; - } - } - return(result); -} - -internal b32 -erase_u32_Ptr_table(u32_Ptr_Table *table, u32*key){ - i32 max = table->max; - if (max > 0 && table->count > 0){ - u64 hash = 0; - block_copy(&hash, key, 4); - if (hash >= 18446744073709551614ULL){ hash += 2; } - i32 first_index = hash%max; - i32 index = first_index; - u64 *hashes = table->hashes; - for (;;){ - if (hashes[index] == 18446744073709551615ULL) break; - if (hashes[index] == hash){ - hashes[index] = 18446744073709551614ULL; - table->count -= 1; - return(true); - } - index = (index + 1)%max; - if (index == first_index) break; - } - } - return(false); -} - -internal b32 -move_u32_Ptr_table(u32_Ptr_Table *dst_table, u32_Ptr_Table *src_table){ - if ((src_table->count + dst_table->count)*8 <= dst_table->max*7){ - i32 max = src_table->max; - u64 *hashes = src_table->hashes; - for (i32 index = 0; index < max; index += 1){ - if (hashes[index] != 18446744073709551615ULL && hashes[index] != 18446744073709551614ULL){ - u32 key_; - u32*key = &key_; - block_copy(key, &hashes[index], 4); - void**val = &src_table->vals[index]; - insert_u32_Ptr_table(dst_table, key, val); - } - } - return(true); - } - return(false); -} - -internal b32 -lookup_u32_Ptr_table(u32_Ptr_Table *table, u32 *key, void* *val_out){ - u32_Ptr_Lookup_Result result = lookup_u32_Ptr_table(table, key); - if (result.success){ - *val_out = *result.val; - } - return(result.success); -} - -internal b32 -insert_u32_Ptr_table(u32_Ptr_Table *table, u32*key, void* val){ - return(insert_u32_Ptr_table(table, key, &val)); -} - -internal b32 -insert_u32_Ptr_table(u32_Ptr_Table *table, u32 key, void**val){ - return(insert_u32_Ptr_table(table, &key, val)); -} - -internal b32 -insert_u32_Ptr_table(u32_Ptr_Table *table, u32 key, void* val){ - return(insert_u32_Ptr_table(table, &key, &val)); -} - -internal u32_Ptr_Lookup_Result -lookup_u32_Ptr_table(u32_Ptr_Table *table, u32 key){ - return(lookup_u32_Ptr_table(table, &key)); -} - -internal b32 -lookup_u32_Ptr_table(u32_Ptr_Table *table, u32 key, void* *val_out){ - return(lookup_u32_Ptr_table(table, &key, val_out)); -} - -internal b32 -erase_u32_Ptr_table(u32_Ptr_Table *table, u32 key){ - return(erase_u32_Ptr_table(table, &key)); -} - -//////////////////////////////// - -internal void -insert_u32_Ptr_table(Heap *heap, u32_Ptr_Table *table, u32 key, void* val){ - if (at_max_u32_Ptr_table(table)){ - i32 new_max = (table->max + 1)*2; - i32 new_mem_size = max_to_memsize_u32_Ptr_table(new_max); - void *new_mem = heap_allocate(heap, new_mem_size); - u32_Ptr_Table new_table = make_u32_Ptr_table(new_mem, new_mem_size); - if (table->mem != 0){ - b32 result = move_u32_Ptr_table(&new_table, table); - Assert(result); - heap_free(heap, table->mem); - } - *table = new_table; - } - b32 result = insert_u32_Ptr_table(table, &key, &val); - Assert(result); -} - -// BOTTOM - diff --git a/4ed_ptr_check.h b/4ed_ptr_check.h deleted file mode 100644 index 28e3d6a4..00000000 --- a/4ed_ptr_check.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 26.08.2018 - * - * Pointer check table - * - */ - -// TOP - -#if !defined(FRED_POINTER_CHECK_H) -#define FRED_POINTER_CHECK_H - -struct Ptr_Table{ - void *mem; - u64 *hashes; - i32 count; - i32 dirty_slot_count; - i32 max; -}; - -struct u32_Ptr_Lookup_Result{ - b32 success; - void**val; -}; -struct u32_Ptr_Table{ - void *mem; - u64 *hashes; - void**vals; - i32 count; - i32 dirty_slot_count; - i32 max; -}; - -#endif - -// BOTTOM - diff --git a/4ed_view.cpp b/4ed_view.cpp index 1d923e2b..298dbd16 100644 --- a/4ed_view.cpp +++ b/4ed_view.cpp @@ -40,7 +40,7 @@ view_get_id(Live_Views *live_set, View *view){ } internal View* -live_set_alloc_view(Heap *heap, Lifetime_Allocator *lifetime_allocator, Live_Views *live_set, Panel *panel){ +live_set_alloc_view(Lifetime_Allocator *lifetime_allocator, Live_Views *live_set, Panel *panel){ Assert(live_set->count < live_set->max); ++live_set->count; @@ -50,7 +50,7 @@ live_set_alloc_view(Heap *heap, Lifetime_Allocator *lifetime_allocator, Live_Vie result->in_use = true; init_query_set(&result->query_set); - result->lifetime_object = lifetime_alloc_object(heap, lifetime_allocator, DynamicWorkspace_View, result); + result->lifetime_object = lifetime_alloc_object(lifetime_allocator, DynamicWorkspace_View, result); panel->view = result; result->panel = panel; @@ -58,7 +58,7 @@ live_set_alloc_view(Heap *heap, Lifetime_Allocator *lifetime_allocator, Live_Vie } internal void -live_set_free_view(Heap *heap, Lifetime_Allocator *lifetime_allocator, Live_Views *live_set, View *view){ +live_set_free_view(Lifetime_Allocator *lifetime_allocator, Live_Views *live_set, View *view){ Assert(live_set->count > 0); --live_set->count; @@ -68,7 +68,7 @@ live_set_free_view(Heap *heap, Lifetime_Allocator *lifetime_allocator, Live_View view->next->prev = view; view->in_use = false; - lifetime_free_object(heap, lifetime_allocator, view->lifetime_object); + lifetime_free_object(lifetime_allocator, view->lifetime_object); } //////////////////////////////// @@ -465,7 +465,7 @@ finalize_color(Color_Table color_table, int_color color){ } internal u32 -get_token_color(Color_Table color_table, Cpp_Token token){ +get_token_color(Color_Table color_table, Token token){ u32 result = 0; if ((token.flags & CPP_TFLAG_IS_KEYWORD) != 0){ if (cpp_token_category_from_type(token.type) == CPP_TOKEN_CAT_BOOLEAN_CONSTANT){ @@ -568,7 +568,7 @@ render_loaded_file_in_view__inner(Models *models, Render_Target *target, View *v // NOTE(allen): Token scanning u32 highlight_this_color = 0; if (tokens_use && ind != prev_ind){ - Cpp_Token current_token = token_array.tokens[token_i-1]; + Token current_token = token_array.tokens[token_i-1]; if (token_i < token_array.count){ if (ind >= token_array.tokens[token_i].start){ diff --git a/4ed_working_set.cpp b/4ed_working_set.cpp index cc07fefb..5afc2259 100644 --- a/4ed_working_set.cpp +++ b/4ed_working_set.cpp @@ -183,7 +183,7 @@ working_set_contains_name(Working_Set *working_set, String_Const_u8 name){ } internal b32 -working_set_add_name(Heap *heap, Working_Set *working_set, Editing_File *file, String_Const_u8 name){ +working_set_add_name(Working_Set *working_set, Editing_File *file, String_Const_u8 name){ return(working_set_add__generic(&working_set->name_table, file->id, name)); } @@ -287,7 +287,7 @@ get_canon_name(System_Functions *system, Arena *scratch, String_Const_u8 file_na } internal void -file_bind_file_name(System_Functions *system, Heap *heap, Working_Set *working_set, Editing_File *file, String_Const_u8 canon_file_name){ +file_bind_file_name(System_Functions *system, Working_Set *working_set, Editing_File *file, String_Const_u8 canon_file_name){ Assert(file->unique_name.name_size == 0); Assert(file->canon.name_size == 0); umem size = canon_file_name.size; @@ -349,7 +349,7 @@ buffer_resolve_name_low_level(Arena *scratch, Working_Set *working_set, Editing_ } internal void -buffer_bind_name_low_level(Arena *scratch, Heap *heap, Working_Set *working_set, Editing_File *file, String_Const_u8 base_name, String_Const_u8 name){ +buffer_bind_name_low_level(Arena *scratch, Working_Set *working_set, Editing_File *file, String_Const_u8 base_name, String_Const_u8 name){ Assert(file->base_name.name_size == 0); Assert(file->unique_name.name_size == 0); @@ -369,7 +369,7 @@ buffer_bind_name_low_level(Arena *scratch, Heap *heap, Working_Set *working_set, file->unique_name.name_size = size; } - b32 result = working_set_add_name(heap, working_set, file, string_from_file_name(&file->unique_name)); + b32 result = working_set_add_name(working_set, file, string_from_file_name(&file->unique_name)); Assert(result); } @@ -383,7 +383,7 @@ buffer_unbind_name_low_level(Working_Set *working_set, Editing_File *file){ } internal void -buffer_bind_name(Models *models, Heap *heap, Arena *scratch, Working_Set *working_set, Editing_File *file, String_Const_u8 base_name){ +buffer_bind_name(Models *models, Arena *scratch, Working_Set *working_set, Editing_File *file, String_Const_u8 base_name){ Temp_Memory temp = begin_temp(scratch); // List of conflict files. @@ -471,7 +471,7 @@ buffer_bind_name(Models *models, Heap *heap, Arena *scratch, Working_Set *workin Editing_File *file_ptr = node->file_ptr; Buffer_Name_Conflict_Entry *entry = &conflicts[i]; String_Const_u8 unique_name = SCu8(entry->unique_name_in_out, entry->unique_name_len_in_out); - buffer_bind_name_low_level(scratch, heap, working_set, file_ptr, base_name, unique_name); + buffer_bind_name_low_level(scratch, working_set, file_ptr, base_name, unique_name); } } diff --git a/languages/4coder_language_cpp.h b/languages/4coder_language_cpp.h index 63911694..c271136f 100644 --- a/languages/4coder_language_cpp.h +++ b/languages/4coder_language_cpp.h @@ -7,6 +7,25 @@ #if !defined(FCODER_LANGUAGE_CPP_H) #define FCODER_LANGUAGE_CPP_H +// TODO(allen): Organize this better! + +internal Token_Array +lex_cpp_initial(Base_Allocator *allocator, String_Const_u8 contents){ + Token_Array result = {}; + result.tokens = base_array(allocator, Token, 2); + result.count = 2; + result.max = 2; + result.tokens[0].pos = 0; + result.tokens[0].size = contents.size; + result.tokens[0].kind = TokenBaseKind_COUNT; + result.tokens[0].sub_kind = 0; + result.tokens[1].pos = contents.size; + result.tokens[1].size = 0; + result.tokens[1].kind = TokenBaseKind_EOF; + return(result); +} + +#if 0 static Parse_Context_ID parse_context_language_cpp; #define PSAT(s, t) {s, sizeof(s)-1, t} @@ -152,6 +171,7 @@ init_language_cpp(Application_Links *app){ parse_context_language_cpp = create_parse_context(app, kw, ArrayCount(kw), pp, ArrayCount(pp)); } #undef PSAT +#endif #endif diff --git a/languages/4coder_language_cs.h b/languages/4coder_language_cs.h index 3b4f2d56..4c96b063 100644 --- a/languages/4coder_language_cs.h +++ b/languages/4coder_language_cs.h @@ -7,6 +7,7 @@ #if !defined(FCODER_LANGUAGE_CS_H) #define FCODER_LANGUAGE_CS_H +#if 0 static Parse_Context_ID parse_context_language_cs; #define PSAT(s, t) {s, sizeof(s)-1, t} @@ -113,6 +114,7 @@ init_language_cs(Application_Links *app){ parse_context_language_cs = create_parse_context(app, kw, ArrayCount(kw), pp, ArrayCount(pp)); } #undef PSAT +#endif #endif diff --git a/languages/4coder_language_java.h b/languages/4coder_language_java.h index 4698cfd7..2d68e8d6 100644 --- a/languages/4coder_language_java.h +++ b/languages/4coder_language_java.h @@ -7,6 +7,7 @@ #if !defined(FCODER_LANGUAGE_JAVA_H) #define FCODER_LANGUAGE_JAVA_H +#if 0 static Parse_Context_ID parse_context_language_java; #define PSAT(s, t) {s, sizeof(s)-1, t} @@ -73,6 +74,7 @@ init_language_java(Application_Links *app){ parse_context_language_java = create_parse_context(app, kw, ArrayCount(kw), 0, 0); } #undef PSAT +#endif #endif diff --git a/languages/4coder_language_rust.h b/languages/4coder_language_rust.h index fc668ed8..98747785 100644 --- a/languages/4coder_language_rust.h +++ b/languages/4coder_language_rust.h @@ -7,6 +7,7 @@ #if !defined(FCODER_LANGUAGE_RUST_H) #define FCODER_LANGUAGE_RUST_H +#if 0 static Parse_Context_ID parse_context_language_rust; #define PSAT(s, t) {s, sizeof(s)-1, t} @@ -73,6 +74,7 @@ init_language_rust(Application_Links *app){ parse_context_language_rust = create_parse_context(app, kw, ArrayCount(kw), 0, 0); } #undef PSAT +#endif #endif diff --git a/meta/4ed_meta_parser.cpp b/meta/4ed_meta_parser.cpp index 9b228436..e5aae02d 100644 --- a/meta/4ed_meta_parser.cpp +++ b/meta/4ed_meta_parser.cpp @@ -13,9 +13,9 @@ #define FRED_META_PARSER_CPP struct Parse_Context{ - Cpp_Token *token_s; - Cpp_Token *token_e; - Cpp_Token *token; + Token *token_s; + Token *token_e; + Token *token; char *data; }; @@ -101,7 +101,7 @@ struct Item_Set{ struct Parse{ String_Const_char code; //String code; - Cpp_Token_Array tokens; + Token_Array tokens; i32 item_count; }; @@ -131,13 +131,13 @@ SCchar_range(char *data, i32 start, i32 end){ } internal String_Const_char -get_lexeme(Cpp_Token token, char *code){ +get_lexeme(Token token, char *code){ String_Const_char str = SCchar(code + token.start, token.size); return(str); } internal Parse_Context -setup_parse_context(char *data, Cpp_Token_Array array){ +setup_parse_context(char *data, Token_Array array){ Parse_Context context; context.token_s = array.tokens; context.token_e = array.tokens + array.count; @@ -156,18 +156,18 @@ setup_parse_context(Parse parse){ return(context); } -internal Cpp_Token* +internal Token* get_token(Parse_Context *context){ - Cpp_Token *result = context->token; + Token *result = context->token; if (result >= context->token_e){ result = 0; } return(result); } -internal Cpp_Token* +internal Token* get_next_token(Parse_Context *context){ - Cpp_Token *result = context->token+1; + Token *result = context->token+1; context->token = result; if (result >= context->token_e){ result = 0; @@ -176,9 +176,9 @@ get_next_token(Parse_Context *context){ return(result); } -internal Cpp_Token* +internal Token* get_prev_token(Parse_Context *context){ - Cpp_Token *result = context->token-1; + Token *result = context->token-1; if (result < context->token_s){ result = 0; } @@ -188,18 +188,18 @@ get_prev_token(Parse_Context *context){ return(result); } -internal Cpp_Token* +internal Token* can_back_step(Parse_Context *context){ - Cpp_Token *result = context->token-1; + Token *result = context->token-1; if (result < context->token_s){ result = 0; } return(result); } -internal Cpp_Token* -set_token(Parse_Context *context, Cpp_Token *token){ - Cpp_Token *result = 0; +internal Token* +set_token(Parse_Context *context, Token *token){ + Token *result = 0; if (token >= context->token_s && token < context->token_e){ context->token = token; result = token; @@ -321,7 +321,7 @@ get_doc_string_from_prev(Parse_Context *context, String_Const_char *doc_string){ i32 result = false; if (can_back_step(context)){ - Cpp_Token *prev_token = get_token(context) - 1; + Token *prev_token = get_token(context) - 1; if (prev_token->type == CPP_TOKEN_COMMENT){ *doc_string = get_lexeme(*prev_token, context->data); if (check_and_fix_docs(doc_string)){ @@ -546,12 +546,12 @@ internal i32 struct_parse_member(Parse_Context *context, Item_Node *member){ i32 result = false; - Cpp_Token *token = get_token(context); + Token *token = get_token(context); String_Const_char doc_string = {}; get_doc_string_from_prev(context, &doc_string); - Cpp_Token *start_token = token; + Token *start_token = token; for (; (token = get_token(context)) != 0; get_next_token(context)){ if (token->type == CPP_TOKEN_SEMICOLON){ @@ -561,7 +561,7 @@ struct_parse_member(Parse_Context *context, Item_Node *member){ if (token){ String_Const_char name = {}; - Cpp_Token *token_j = 0; + Token *token_j = 0; i32 nest_level = 0; for (; (token_j = get_token(context)) > start_token; get_prev_token(context)){ @@ -606,7 +606,7 @@ internal Item_Node* struct_parse_next_member(Arena *arena, Parse_Context *context){ Item_Node *result = 0; - Cpp_Token *token = 0; + Token *token = 0; for (; (token = get_token(context)) != 0; get_next_token(context)){ if (token->type == CPP_TOKEN_IDENTIFIER || @@ -656,8 +656,8 @@ internal i32 struct_parse(Arena *arena, i32 is_struct, Parse_Context *context, Item_Node *top_member){ i32 result = false; - Cpp_Token *start_token = get_token(context); - Cpp_Token *token = 0; + Token *start_token = get_token(context); + Token *token = 0; String_Const_char doc_string = {}; get_doc_string_from_prev(context, &doc_string); @@ -669,7 +669,7 @@ struct_parse(Arena *arena, i32 is_struct, Parse_Context *context, Item_Node *top } if (token){ - Cpp_Token *token_j = token; + Token *token_j = token; for (; (token_j = get_token(context)) > start_token; get_prev_token(context)){ if (token_j->type == CPP_TOKEN_IDENTIFIER){ @@ -737,11 +737,11 @@ internal i32 typedef_parse(Parse_Context *context, Item_Node *item){ i32 result = false; - Cpp_Token *token = get_token(context); + Token *token = get_token(context); String_Const_char doc_string = {}; get_doc_string_from_prev(context, &doc_string); - Cpp_Token *start_token = token; + Token *start_token = token; for (; (token = get_token(context)) != 0; get_next_token(context)){ if (token->type == CPP_TOKEN_SEMICOLON){ @@ -750,7 +750,7 @@ typedef_parse(Parse_Context *context, Item_Node *item){ } if (token){ - Cpp_Token *token_j = token; + Token *token_j = token; for (; (token_j = get_token(context)) > start_token; get_prev_token(context)){ if (token_j->type == CPP_TOKEN_IDENTIFIER){ @@ -781,8 +781,8 @@ enum_parse(Arena *arena, Parse_Context *context, Item_Node *item){ String_Const_char parent_doc_string = {}; get_doc_string_from_prev(context, &parent_doc_string); - Cpp_Token *parent_start_token = get_token(context); - Cpp_Token *token = 0; + Token *parent_start_token = get_token(context); + Token *token = 0; for (; (token = get_token(context)) != 0; get_next_token(context)){ if (token->type == CPP_TOKEN_BRACE_OPEN){ @@ -792,7 +792,7 @@ enum_parse(Arena *arena, Parse_Context *context, Item_Node *item){ if (token){ String_Const_char parent_name = {}; - Cpp_Token *token_j = 0; + Token *token_j = 0; for (; (token_j = get_token(context)) != 0; get_prev_token(context)){ if (token_j->type == CPP_TOKEN_IDENTIFIER){ @@ -829,7 +829,7 @@ enum_parse(Arena *arena, Parse_Context *context, Item_Node *item){ if (token){ if (token->type == CPP_TOKEN_EQ){ - Cpp_Token *start_token = token; + Token *start_token = token; for (; (token = get_token(context)) != 0; get_next_token(context)){ if (token->type == CPP_TOKEN_COMMA || @@ -901,9 +901,9 @@ foo(a, ... , z) ^ ^ */ internal Argument_Breakdown -parameter_parse(Arena *arena, char *data, Cpp_Token *args_start_token, Cpp_Token *args_end_token){ +parameter_parse(Arena *arena, char *data, Token *args_start_token, Token *args_end_token){ i32 arg_index = 0; - Cpp_Token *arg_token = args_start_token + 1; + Token *arg_token = args_start_token + 1; i32 param_string_start = arg_token->start; i32 arg_count = 1; @@ -926,7 +926,7 @@ parameter_parse(Arena *arena, char *data, Cpp_Token *args_start_token, Cpp_Token param_string = string_chop_whitespace(param_string); breakdown.args[arg_index].param_string = param_string; - for (Cpp_Token *param_name_token = arg_token - 1; + for (Token *param_name_token = arg_token - 1; param_name_token->start > param_string_start; --param_name_token){ if (param_name_token->type == CPP_TOKEN_IDENTIFIER){ @@ -957,7 +957,7 @@ internal i32 function_parse_goto_name(Parse_Context *context){ i32 result = false; - Cpp_Token *token = 0; + Token *token = 0; { for (; (token = get_token(context)) != 0; get_next_token(context)){ @@ -989,7 +989,7 @@ internal i32 function_get_doc(Parse_Context *context, char *data, String_Const_char *doc_string){ i32 result = false; - Cpp_Token *token = get_token(context); + Token *token = get_token(context); String_Const_char lexeme = {}; if (function_parse_goto_name(context)){ @@ -1017,8 +1017,8 @@ internal i32 cpp_name_parse(Parse_Context *context, String_Const_char *name){ i32 result = false; - Cpp_Token *token = 0; - Cpp_Token *token_start = get_token(context); + Token *token = 0; + Token *token_start = get_token(context); token = get_next_token(context); if (token && token->type == CPP_TOKEN_PARENTHESE_OPEN){ @@ -1048,9 +1048,9 @@ internal i32 function_sig_parse(Arena *arena, Parse_Context *context, Item_Node *item, String_Const_char cpp_name){ i32 result = false; - Cpp_Token *token = 0; - Cpp_Token *args_start_token = 0; - Cpp_Token *ret_token = get_token(context); + Token *token = 0; + Token *args_start_token = 0; + Token *ret_token = get_token(context); if (function_parse_goto_name(context)){ token = get_token(context); @@ -1089,7 +1089,7 @@ function_parse(Arena *arena, Parse_Context *context, Item_Node *item, String_Con i32 result = false; String_Const_char doc_string = {}; - Cpp_Token *token = get_token(context); + Token *token = get_token(context); item->marker = get_lexeme(*token, context->data); @@ -1117,7 +1117,7 @@ internal i32 macro_parse_check(Parse_Context *context){ i32 result = false; - Cpp_Token *token = 0; + Token *token = 0; if ((token = get_next_token(context)) != 0){ if (token->type == CPP_TOKEN_COMMENT){ @@ -1141,9 +1141,9 @@ internal i32 macro_parse(Arena *arena, Parse_Context *context, Item_Node *item){ i32 result = false; - Cpp_Token *token = 0; - Cpp_Token *doc_token = 0; - Cpp_Token *args_start_token = 0; + Token *token = 0; + Token *doc_token = 0; + Token *args_start_token = 0; String_Const_char doc_string = {}; @@ -1180,7 +1180,7 @@ macro_parse(Arena *arena, Parse_Context *context, Item_Node *item){ item->breakdown = parameter_parse(arena, context->data, args_start_token, token); if ((token = get_next_token(context)) != 0){ - Cpp_Token *body_start = token; + Token *body_start = token; if (body_start->flags & CPP_TFLAG_PP_BODY){ for (; (token = get_token(context)) != 0; get_next_token(context)){ @@ -1240,7 +1240,7 @@ compile_meta_unit(Arena *arena, char *code_directory, char **files, Meta_Keyword if (all_files_lexed){ // TODO(allen): This stage counts nested structs and unions which is not correct. Luckily it only means we over allocate by a few items, but fixing it to be exactly correct would be nice. for (i32 J = 0; J < unit.count; ++J){ - Cpp_Token *token = 0; + Token *token = 0; Parse_Context context_ = setup_parse_context(unit.parse[J]); Parse_Context *context = &context_; @@ -1270,7 +1270,7 @@ compile_meta_unit(Arena *arena, char *code_directory, char **files, Meta_Keyword i32 index = 0; for (i32 J = 0; J < unit.count; ++J){ - Cpp_Token *token = 0; + Token *token = 0; Parse_Context context_ = setup_parse_context(unit.parse[J]); Parse_Context *context = &context_; diff --git a/meta/4ed_metagen.cpp b/meta/4ed_metagen.cpp index d84a48b6..d039b4c5 100644 --- a/meta/4ed_metagen.cpp +++ b/meta/4ed_metagen.cpp @@ -20,7 +20,6 @@ #include "4coder_base_types.cpp" #include "4coder_stringf.cpp" # define FSTRING_IMPLEMENTATION -# include "4coder_lib/4coder_string.h" #include "4coder_lib/4cpp_lexer.h" #include diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index b1303a64..4b9ab081 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -28,9 +28,6 @@ #include "4coder_lib/4coder_utf8.h" #if defined(FRED_SUPER) -# include "4coder_lib/4coder_heap.h" -# include "4coder_lib/4coder_heap.cpp" - # include "4coder_base_types.cpp" # include "4coder_stringf.cpp" # include "4coder_hash_functions.cpp"