Setting up lifetime buckets

This commit is contained in:
Allen Webster 2018-08-10 22:42:00 -07:00
parent f0b9b76d9f
commit b4b19886f3
8 changed files with 78 additions and 43 deletions

View File

@ -691,15 +691,18 @@ STRUCT Query_Bar{
static int32_t CoreVariableIndex_ERROR = -1; static int32_t CoreVariableIndex_ERROR = -1;
ENUM(int32_t, Lifetime_Type){ ENUM(int32_t, Lifetime_Handle_Type){
LifetimeType_View = 0, LifetimeHandleType_Overlapped = 0,
LifetimeType_Buffer = 1, LifetimeHandleType_Buffer = 1,
LifetimeHandleType_View = 2,
}; };
STRUCT Lifetime_Handle{ STRUCT Lifetime_Handle{
Lifetime_Type type; Lifetime_Handle_Type type;
View_ID view_id; union{
Buffer_ID buffer_id; View_ID view_id;
Buffer_ID buffer_id;
};
}; };
ENUM(int16_t, UI_Item_Type){ ENUM(int16_t, UI_Item_Type){

View File

@ -247,10 +247,10 @@ default_4coder_initialize(Application_Links *app, int32_t override_font_size, bo
load_folder_of_themes_into_live_set(app, &global_part, "themes"); load_folder_of_themes_into_live_set(app, &global_part, "themes");
load_config_and_apply(app, &global_part, &global_config, override_font_size, override_hinting); load_config_and_apply(app, &global_part, &global_config, override_font_size, override_hinting);
view_rewrite_loc = create_core_variable(app, LifetimeType_View, "DEFAULT.rewrite" , (uint64_t)0); view_rewrite_loc = create_core_variable(app, "DEFAULT.rewrite" , (uint64_t)0);
view_next_rewrite_loc = create_core_variable(app, LifetimeType_View, "DEFAULT.next_rewrite", (uint64_t)0); view_next_rewrite_loc = create_core_variable(app, "DEFAULT.next_rewrite", (uint64_t)0);
view_paste_index_loc = create_core_variable(app, LifetimeType_View, "DEFAULT.paste_index" , (uint64_t)0); view_paste_index_loc = create_core_variable(app, "DEFAULT.paste_index" , (uint64_t)0);
view_is_passive_loc = create_core_variable(app, LifetimeType_View, "DEFAULT.is_passive" , (uint64_t)false); view_is_passive_loc = create_core_variable(app, "DEFAULT.is_passive" , (uint64_t)false);
} }
static void static void

View File

@ -55,7 +55,7 @@ struct Application_Links;
#define VIEW_END_UI_MODE_SIG(n) int32_t n(Application_Links *app, View_Summary *view) #define VIEW_END_UI_MODE_SIG(n) int32_t n(Application_Links *app, View_Summary *view)
#define VIEW_SET_UI_SIG(n) bool32 n(Application_Links *app, View_Summary *view, UI_Control *control) #define VIEW_SET_UI_SIG(n) bool32 n(Application_Links *app, View_Summary *view, UI_Control *control)
#define VIEW_GET_UI_COPY_SIG(n) UI_Control n(Application_Links *app, View_Summary *view, struct Partition *part) #define VIEW_GET_UI_COPY_SIG(n) UI_Control n(Application_Links *app, View_Summary *view, struct Partition *part)
#define CREATE_CORE_VARIABLE_SIG(n) int32_t n(Application_Links *app, Lifetime_Type type, char *null_terminated_name, uint64_t default_value) #define CREATE_CORE_VARIABLE_SIG(n) int32_t n(Application_Links *app, char *null_terminated_name, uint64_t default_value)
#define CORE_VARIABLE_SET_SIG(n) bool32 n(Application_Links *app, Lifetime_Handle handle, int32_t location, uint64_t value) #define CORE_VARIABLE_SET_SIG(n) bool32 n(Application_Links *app, Lifetime_Handle handle, int32_t location, uint64_t value)
#define CORE_VARIABLE_GET_SIG(n) bool32 n(Application_Links *app, Lifetime_Handle handle, int32_t location, uint64_t *value_out) #define CORE_VARIABLE_GET_SIG(n) bool32 n(Application_Links *app, Lifetime_Handle handle, int32_t location, uint64_t *value_out)
#define GET_USER_INPUT_SIG(n) User_Input n(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type) #define GET_USER_INPUT_SIG(n) User_Input n(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type)
@ -558,7 +558,7 @@ static inline int32_t view_start_ui_mode(Application_Links *app, View_Summary *v
static inline int32_t view_end_ui_mode(Application_Links *app, View_Summary *view){return(app->view_end_ui_mode(app, view));} static inline int32_t view_end_ui_mode(Application_Links *app, View_Summary *view){return(app->view_end_ui_mode(app, view));}
static inline bool32 view_set_ui(Application_Links *app, View_Summary *view, UI_Control *control){return(app->view_set_ui(app, view, control));} static inline bool32 view_set_ui(Application_Links *app, View_Summary *view, UI_Control *control){return(app->view_set_ui(app, view, control));}
static inline UI_Control view_get_ui_copy(Application_Links *app, View_Summary *view, struct Partition *part){return(app->view_get_ui_copy(app, view, part));} static inline UI_Control view_get_ui_copy(Application_Links *app, View_Summary *view, struct Partition *part){return(app->view_get_ui_copy(app, view, part));}
static inline int32_t create_core_variable(Application_Links *app, Lifetime_Type type, char *null_terminated_name, uint64_t default_value){return(app->create_core_variable(app, type, null_terminated_name, default_value));} static inline int32_t create_core_variable(Application_Links *app, char *null_terminated_name, uint64_t default_value){return(app->create_core_variable(app, null_terminated_name, default_value));}
static inline bool32 core_variable_set(Application_Links *app, Lifetime_Handle handle, int32_t location, uint64_t value){return(app->core_variable_set(app, handle, location, value));} static inline bool32 core_variable_set(Application_Links *app, Lifetime_Handle handle, int32_t location, uint64_t value){return(app->core_variable_set(app, handle, location, value));}
static inline bool32 core_variable_get(Application_Links *app, Lifetime_Handle handle, int32_t location, uint64_t *value_out){return(app->core_variable_get(app, handle, location, value_out));} static inline bool32 core_variable_get(Application_Links *app, Lifetime_Handle handle, int32_t location, uint64_t *value_out){return(app->core_variable_get(app, handle, location, value_out));}
static inline User_Input get_user_input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type){return(app->get_user_input(app, get_type, abort_type));} static inline User_Input get_user_input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type){return(app->get_user_input(app, get_type, abort_type));}
@ -657,7 +657,7 @@ static inline int32_t view_start_ui_mode(Application_Links *app, View_Summary *v
static inline int32_t view_end_ui_mode(Application_Links *app, View_Summary *view){return(app->view_end_ui_mode_(app, view));} static inline int32_t view_end_ui_mode(Application_Links *app, View_Summary *view){return(app->view_end_ui_mode_(app, view));}
static inline bool32 view_set_ui(Application_Links *app, View_Summary *view, UI_Control *control){return(app->view_set_ui_(app, view, control));} static inline bool32 view_set_ui(Application_Links *app, View_Summary *view, UI_Control *control){return(app->view_set_ui_(app, view, control));}
static inline UI_Control view_get_ui_copy(Application_Links *app, View_Summary *view, struct Partition *part){return(app->view_get_ui_copy_(app, view, part));} static inline UI_Control view_get_ui_copy(Application_Links *app, View_Summary *view, struct Partition *part){return(app->view_get_ui_copy_(app, view, part));}
static inline int32_t create_core_variable(Application_Links *app, Lifetime_Type type, char *null_terminated_name, uint64_t default_value){return(app->create_core_variable_(app, type, null_terminated_name, default_value));} static inline int32_t create_core_variable(Application_Links *app, char *null_terminated_name, uint64_t default_value){return(app->create_core_variable_(app, null_terminated_name, default_value));}
static inline bool32 core_variable_set(Application_Links *app, Lifetime_Handle handle, int32_t location, uint64_t value){return(app->core_variable_set_(app, handle, location, value));} static inline bool32 core_variable_set(Application_Links *app, Lifetime_Handle handle, int32_t location, uint64_t value){return(app->core_variable_set_(app, handle, location, value));}
static inline bool32 core_variable_get(Application_Links *app, Lifetime_Handle handle, int32_t location, uint64_t *value_out){return(app->core_variable_get_(app, handle, location, value_out));} static inline bool32 core_variable_get(Application_Links *app, Lifetime_Handle handle, int32_t location, uint64_t *value_out){return(app->core_variable_get_(app, handle, location, value_out));}
static inline User_Input get_user_input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type){return(app->get_user_input_(app, get_type, abort_type));} static inline User_Input get_user_input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type){return(app->get_user_input_(app, get_type, abort_type));}

View File

@ -1072,16 +1072,14 @@ App_Init_Sig(app_init){
{ {
setup_command_table(); setup_command_table();
Assert(models->config_api.get_bindings != 0); Assert(models->config_api.get_bindings != 0);
i32 wanted_size = models->config_api.get_bindings(models->app_links.memory, models->app_links.memory_size); i32 wanted_size = models->config_api.get_bindings(models->app_links.memory, models->app_links.memory_size);
Assert(wanted_size <= models->app_links.memory_size); Assert(wanted_size <= models->app_links.memory_size);
interpret_binding_buffer(models, models->app_links.memory, wanted_size); interpret_binding_buffer(models, models->app_links.memory, wanted_size);
memset(models->app_links.memory, 0, wanted_size); memset(models->app_links.memory, 0, wanted_size);
} }
dynamic_variables_init(&models->view_variable_layout); dynamic_variables_init(&models->variable_layout);
// NOTE(allen): file setup // NOTE(allen): file setup
working_set_init(&models->working_set, partition, &vars->models.mem.general); working_set_init(&models->working_set, partition, &vars->models.mem.general);

View File

@ -1202,7 +1202,7 @@ Buffer_Get_Lifetime_Handle(Application_Links *app, Buffer_ID buffer_id)
Editing_File *file = imp_get_file(cmd, buffer_id); Editing_File *file = imp_get_file(cmd, buffer_id);
Lifetime_Handle lifetime = {0}; Lifetime_Handle lifetime = {0};
if (file != 0){ if (file != 0){
lifetime.type = LifetimeType_Buffer; lifetime.type = LifetimeHandleType_Buffer;
lifetime.buffer_id = buffer_id; lifetime.buffer_id = buffer_id;
} }
return(lifetime); return(lifetime);
@ -1946,7 +1946,7 @@ View_Get_Lifetime_Handle(Application_Links *app, View_ID view_id)
View *view = imp_get_view(cmd, view_id); View *view = imp_get_view(cmd, view_id);
Lifetime_Handle lifetime = {0}; Lifetime_Handle lifetime = {0};
if (view != 0){ if (view != 0){
lifetime.type = LifetimeType_View; lifetime.type = LifetimeHandleType_View;
lifetime.view_id = view_id; lifetime.view_id = view_id;
} }
return(lifetime); return(lifetime);
@ -2355,26 +2355,24 @@ View_Get_UI_Copy(Application_Links *app, View_Summary *view, struct Partition *p
return(result); return(result);
} }
API_EXPORT Lifetime_Handle
Get_Overlapped_Lifetime_Handle(Application_Links *app, Lifetime_Handle *member_handles, int32_t member_count)
{
Command_Data *cmd = (Command_Data*)app->cmd_context;
Lifetime_Handle result = {0};
return(result);
}
API_EXPORT int32_t API_EXPORT int32_t
Create_Core_Variable(Application_Links *app, Lifetime_Type type, char *null_terminated_name, uint64_t default_value) Create_Core_Variable(Application_Links *app, char *null_terminated_name, uint64_t default_value)
{ {
Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
Models *models = cmd->models; Models *models = cmd->models;
String name = make_string_slowly(null_terminated_name); String name = make_string_slowly(null_terminated_name);
General_Memory *general = &models->mem.general; General_Memory *general = &models->mem.general;
switch (type){ Dynamic_Variable_Layout *layout = &models->variable_layout;
case LifetimeType_View: return(dynamic_variables_lookup_or_create(general, layout, name, default_value));
{
Dynamic_Variable_Layout *layout = &models->view_variable_layout;
return(dynamic_variables_lookup_or_create(general, layout, name, default_value));
}break;
case LifetimeType_Buffer:
{
Dynamic_Variable_Layout *layout = &models->buffer_variable_layout;
return(dynamic_variables_lookup_or_create(general, layout, name, default_value));
}break;
}
return(CoreVariableIndex_ERROR);
} }
internal bool32 internal bool32
@ -2382,27 +2380,30 @@ get_dynamic_variable(Command_Data *cmd, Lifetime_Handle handle,
int32_t location, uint64_t **ptr_out){ int32_t location, uint64_t **ptr_out){
Models *models = cmd->models; Models *models = cmd->models;
General_Memory *general = &models->mem.general; General_Memory *general = &models->mem.general;
Dynamic_Variable_Layout *layout = 0; Dynamic_Variable_Layout *layout = &models->variable_layout;
Dynamic_Variable_Block *block = 0; Dynamic_Variable_Block *block = 0;
switch (handle.type){ switch (handle.type){
case LifetimeType_View: case LifetimeHandleType_Overlapped:
{ {
View *vptr = imp_get_view(cmd, handle.view_id); NotImplemented;
if (vptr != 0){
layout = &models->view_variable_layout;
block = &vptr->transient.dynamic_vars;
}
}break; }break;
case LifetimeType_Buffer: case LifetimeHandleType_Buffer:
{ {
Editing_File *file = imp_get_file(cmd, handle.buffer_id); Editing_File *file = imp_get_file(cmd, handle.buffer_id);
if (file != 0){ if (file != 0){
layout = &models->buffer_variable_layout;
block = &file->dynamic_vars; block = &file->dynamic_vars;
} }
}break; }break;
case LifetimeHandleType_View:
{
View *vptr = imp_get_view(cmd, handle.view_id);
if (vptr != 0){
block = &vptr->transient.dynamic_vars;
}
}break;
} }
bool32 result = false; bool32 result = false;

View File

@ -67,8 +67,7 @@ struct Models{
Live_Views live_set; Live_Views live_set;
Parse_Context_Memory parse_context_memory; Parse_Context_Memory parse_context_memory;
Dynamic_Variable_Layout buffer_variable_layout; Dynamic_Variable_Layout variable_layout;
Dynamic_Variable_Layout view_variable_layout;
Editing_File *message_buffer; Editing_File *message_buffer;
Editing_File *scratch_buffer; Editing_File *scratch_buffer;

View File

@ -98,5 +98,9 @@ dynamic_variables_get_ptr(General_Memory *general,
return(result); return(result);
} }
////////////////////////////////
// TODO(allen): // TODO(allen): // TODO(allen):
// BOTTOM // BOTTOM

View File

@ -31,6 +31,36 @@ struct Dynamic_Variable_Block{
i32 max; i32 max;
}; };
////////////////////////////////
union Lifetime_Object{
struct{
Object *next;
Object *prev;
};
struct{
struct Key **keys;
i32 count;
i32 max;
};
};
union Lifetime_Key{
struct{
Key *next;
Key *prev;
};
struct{
struct Object **keys;
i32 count;
i32 max;
};
};
struct Lifetime_Allocator{
// TODO(allen): // TODO(allen): // TODO(allen): // TODO(allen):
};
#endif #endif
// BOTTOM // BOTTOM