Added metaprogram for custom ids to make them much easier to declare and integrate

This commit is contained in:
Allen Webster 2019-11-24 15:13:51 -08:00
parent ebb1e96706
commit f1ddbc2cc8
16 changed files with 765 additions and 657 deletions

25
4ed.cpp
View File

@ -268,6 +268,8 @@ App_Init_Sig(app_init){
profile_init(&models->profile_list);
managed_ids_init(tctx->allocator, &models->managed_id_set);
API_VTable_custom custom_vtable = {};
custom_api_fill_vtable(&custom_vtable);
API_VTable_system system_vtable = {};
@ -275,11 +277,6 @@ App_Init_Sig(app_init){
Custom_Layer_Init_Type *custom_init = api.init_apis(&custom_vtable, &system_vtable);
Assert(custom_init != 0);
Application_Links app = {};
app.tctx = tctx;
app.cmd_context = models;
custom_init(&app);
// NOTE(allen): coroutines
coroutine_system_init(&models->coroutines);
@ -308,13 +305,11 @@ App_Init_Sig(app_init){
}
}
managed_ids_init(tctx->allocator, &models->managed_id_set);
lifetime_allocator_init(tctx->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);
Mutex_Lock file_order_lock(models->working_set.mutex);
// NOTE(allen):
@ -350,6 +345,17 @@ App_Init_Sig(app_init){
models->title_space = push_array(arena, char, models->title_capacity);
block_copy(models->title_space, WINDOW_NAME, sizeof(WINDOW_NAME));
// NOTE(allen): miscellaneous init
hot_directory_init(arena, &models->hot_directory, current_directory);
child_process_container_init(tctx->allocator, &models->child_processes);
models->period_wakeup_timer = system_wake_up_timer_create();
// NOTE(allen): custom layer init
Application_Links app = {};
app.tctx = tctx;
app.cmd_context = models;
custom_init(&app);
// NOTE(allen): init baked in buffers
File_Init init_files[] = {
{ string_u8_litinit("*messages*"), &models->message_buffer , true , },
@ -384,11 +390,6 @@ App_Init_Sig(app_init){
View *new_view = live_set_alloc_view(&models->lifetime_allocator, &models->view_set, panel);
view_init(tctx, models, new_view, models->scratch_buffer, models->view_event_handler);
}
// NOTE(allen): miscellaneous init
hot_directory_init(arena, &models->hot_directory, current_directory);
child_process_container_init(tctx->allocator, &models->child_processes);
models->period_wakeup_timer = system_wake_up_timer_create();
}
App_Step_Sig(app_step){

View File

@ -2019,11 +2019,11 @@ managed_scope_allocator(Application_Links *app, Managed_Scope scope)
}
api(custom) function Managed_ID
managed_id_declare(Application_Links *app, String_Const_u8 name)
managed_id_declare(Application_Links *app, String_Const_u8 group, String_Const_u8 name)
{
Models *models = (Models*)app->cmd_context;
Managed_ID_Set *set = &models->managed_id_set;
return(managed_ids_declare(set, name));
return(managed_ids_declare(set, group, name));
}
api(custom) function void*

View File

@ -15,8 +15,8 @@
#include "4coder_version.h"
#include "4coder_table.h"
#include "4coder_events.h"
#include "4coder_default_colors.h"
#include "4coder_types.h"
#include "4coder_default_colors.h"
#define STATIC_LINK_API
#include "generated/custom_api.h"

View File

@ -12,23 +12,40 @@
internal void
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;
}
set->name_to_group_table = make_table_Data_u64(allocator, 20);
}
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);
managed_ids_declare(Managed_ID_Set *set, String_Const_u8 group_name, String_Const_u8 name){
Managed_ID_Group *group = 0;
{
Data data = make_data(group_name.str, group_name.size);
Table_Lookup lookup = table_lookup(&set->name_to_group_table, data);
if (lookup.found_match){
table_read(&set->name_to_id_table, lookup, &result);
u64 val = 0;
table_read(&set->name_to_group_table, lookup, &val);
group = (Managed_ID_Group*)IntAsPtr(val);
}
else{
result = set->id_counter;
set->id_counter += 1;
group = push_array(&set->arena, Managed_ID_Group, 1);
group->name_to_id_table = make_table_Data_u64(set->arena.base_allocator, 50);
data = push_data_copy(&set->arena, data);
table_insert(&set->name_to_id_table, data, result);
table_insert(&set->name_to_group_table, data, PtrAsInt(group));
}
}
Managed_ID result = 0;
{
Data data = make_data(name.str, name.size);
Table_Lookup lookup = table_lookup(&group->name_to_id_table, data);
if (lookup.found_match){
table_read(&group->name_to_id_table, lookup, &result);
}
else{
result = group->id_counter;
group->id_counter += 1;
data = push_data_copy(&set->arena, data);
table_insert(&group->name_to_id_table, data, result);
}
}
return(result);
}

View File

@ -60,12 +60,16 @@ struct Managed_Arena_Header_List{
////////////////////////////////
struct Managed_ID_Set{
Arena arena;
struct Managed_ID_Group{
Table_Data_u64 name_to_id_table;
Managed_ID id_counter;
};
struct Managed_ID_Set{
Arena arena;
Table_Data_u64 name_to_group_table;
};
struct Dynamic_Variable_Block{
Arena arena;
Table_u64_Data id_to_data_table;

View File

@ -24,6 +24,26 @@ custom_layer_init(Application_Links *app){
Profile_Global_List *list = get_core_profile_list(app);
ProfileThreadName(tctx, list, string_u8_litexpr("main"));
#define BindAttachmentID(N) N = managed_id_declare(app, SCu8("attachment"), SCu8(#N))
BindAttachmentID(view_rewrite_loc);
BindAttachmentID(view_next_rewrite_loc);
BindAttachmentID(view_paste_index_loc);
BindAttachmentID(view_is_passive_loc);
BindAttachmentID(view_snap_mark_to_cursor);
BindAttachmentID(view_ui_data);
BindAttachmentID(view_highlight_range);
BindAttachmentID(view_highlight_buffer);
BindAttachmentID(view_render_hook);
BindAttachmentID(view_word_complete_menu);
BindAttachmentID(buffer_map_id);
BindAttachmentID(buffer_eol_setting);
BindAttachmentID(buffer_lex_task);
BindAttachmentID(sticky_jump_marker_handle);
BindAttachmentID(attachment_tokens);
}
#endif

View File

@ -450,24 +450,6 @@ default_4coder_initialize(Application_Links *app, String_Const_u8_Array file_nam
global_config_arena = reserve_arena(app);
load_config_and_apply(app, global_config_arena, &global_config, override_font_size, override_hinting);
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" ));
view_word_complete_menu = managed_id_declare(app, SCu8("DEFAULT.word_complete_menu"));
buffer_map_id = managed_id_declare(app, SCu8("DEFAULT.buffer_map_id" ));
buffer_eol_setting = managed_id_declare(app, SCu8("DEFAULT.buffer_eol_setting"));
buffer_lex_task = managed_id_declare(app, SCu8("DEFAULT.buffer_lex_task"));
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
Scratch_Block scratch(app);
String_Const_u8 hot_directory = push_hot_directory(app, scratch);

View File

@ -5,6 +5,27 @@ the default 4coder behavior.
// TOP
CUSTOM_ID(attachment, view_rewrite_loc);
CUSTOM_ID(attachment, view_next_rewrite_loc);
CUSTOM_ID(attachment, view_paste_index_loc);
CUSTOM_ID(attachment, view_is_passive_loc);
CUSTOM_ID(attachment, view_snap_mark_to_cursor);
CUSTOM_ID(attachment, view_ui_data);
CUSTOM_ID(attachment, view_highlight_range);
CUSTOM_ID(attachment, view_highlight_buffer);
CUSTOM_ID(attachment, view_render_hook);
CUSTOM_ID(attachment, view_word_complete_menu);
CUSTOM_ID(attachment, buffer_map_id);
CUSTOM_ID(attachment, buffer_eol_setting);
CUSTOM_ID(attachment, buffer_lex_task);
CUSTOM_ID(attachment, buffer_wrap_lines);
CUSTOM_ID(attachment, sticky_jump_marker_handle);
CUSTOM_ID(attachment, attachment_tokens);
////////////////////////////////
global b32 allow_immediate_close_without_checking_for_changes = false;
global char *default_extensions[] = {
@ -30,27 +51,6 @@ global String_Const_u8 locked_buffer = {};
global View_ID build_footer_panel_view_id = 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_ID view_word_complete_menu = 0;
global Managed_ID buffer_map_id = 0;
global Managed_ID buffer_eol_setting = 0;
global Managed_ID buffer_lex_task = 0;
global Managed_ID buffer_wrap_lines = 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];
global char hot_directory_space[1024];

View File

@ -947,15 +947,6 @@ BUFFER_HOOK_SIG(default_begin_buffer){
}
}
local_persist b32 first_call = true;
if (first_call){
first_call = false;
buffer_map_id = managed_id_declare(app, SCu8("DEFAULT.buffer_map_id"));
buffer_eol_setting = managed_id_declare(app, SCu8("DEFAULT.buffer_eol_setting"));
buffer_lex_task = managed_id_declare(app, SCu8("DEFAULT.buffer_lex_task"));
buffer_wrap_lines = managed_id_declare(app, SCu8("DEFAULT.buffer_wrap_lines"));
}
Command_Map_ID map_id = (treat_as_code)?(default_code_map):(mapid_file);
Managed_Scope scope = buffer_get_managed_scope(app, buffer_id);
Command_Map_ID *map_id_ptr = scope_attachment(app, scope, buffer_map_id, Command_Map_ID);

View File

@ -10,9 +10,9 @@
#include "4coder_base_types.h"
#include "4coder_version.h"
#include "4coder_table.h"
#include "4coder_default_colors.h"
#include "4coder_events.h"
#include "4coder_types.h"
#include "4coder_default_colors.h"
#define DYNAMIC_LINK_API
#include "generated/custom_api.h"
#include "4coder_system_types.h"
@ -111,6 +111,8 @@
#include "4coder_default_hooks.cpp"
#include "generated/managed_id_metadata.cpp"
#endif
// BOTTOM

View File

@ -5,6 +5,7 @@
// TOP
#define COMMAND_METADATA_OUT "generated/command_metadata.h"
#define ID_METADATA_OUT "generated/managed_id_metadata.cpp"
#include "4coder_base_types.h"
#include "4coder_token.h"
@ -23,9 +24,6 @@
#include <stdlib.h>
#include <stdint.h>
#define str_to_l_c(s) ((i32)(s).size), ((s).str)
#define str_to_c_l(s) ((s).str), ((i32)(s).size)
///////////////////////////////
struct Line_Column_Coordinates{
@ -33,6 +31,61 @@ struct Line_Column_Coordinates{
i64 column;
};
struct Reader{
Arena *error_arena;
u8 *source_name;
String_Const_u8 text;
Token_Array tokens;
Token *ptr;
};
struct Temp_Read{
Reader *reader;
Token *pos;
};
typedef i32 Meta_Command_Entry_Kind;
enum{
MetaCommandEntryKind_ERROR,
MetaCommandEntryKind_Normal,
MetaCommandEntryKind_UI,
};
struct Meta_Command_Entry{
Meta_Command_Entry *next;
Meta_Command_Entry_Kind kind;
String_Const_u8 name;
u8 *source_name;
i64 line_number;
union{
struct{
String_Const_u8 doc;
} docstring;
};
};
struct Meta_ID_Entry{
Meta_ID_Entry *next;
String_Const_u8 group_name;
String_Const_u8 id_name;
};
struct Meta_Command_Entry_Arrays{
Meta_Command_Entry *first_doc_string;
Meta_Command_Entry *last_doc_string;
i32 doc_string_count;
Meta_Command_Entry *first_ui;
Meta_Command_Entry *last_ui;
i32 ui_count;
Meta_ID_Entry *first_id;
Meta_ID_Entry *last_id;
i32 id_count;
};
///////////////////////////////
static Line_Column_Coordinates
line_column_coordinates(String_Const_u8 text, i64 pos){
if (pos < 0){
@ -75,22 +128,10 @@ error(u8 *source_name, String_Const_u8 text, i64 pos, u8 *msg){
///////////////////////////////
struct Reader{
Arena *error_arena;
u8 *source_name;
String_Const_u8 text;
Token_Array tokens;
Token *ptr;
};
struct Temp_Read{
Reader *reader;
Token *pos;
};
static Reader
make_reader(Token_Array array, u8 *source_name, String_Const_u8 text){
make_reader(Arena *error_arena, Token_Array array, u8 *source_name, String_Const_u8 text){
Reader reader = {};
reader.error_arena = error_arena;
reader.tokens = array;
reader.ptr = array.tokens;
reader.source_name = source_name;
@ -214,38 +255,6 @@ token_str(String_Const_u8 text, Token token){
///////////////////////////////
typedef i32 Meta_Command_Entry_Kind;
enum{
MetaCommandEntryKind_ERROR,
MetaCommandEntryKind_Normal,
MetaCommandEntryKind_UI,
};
struct Meta_Command_Entry{
Meta_Command_Entry *next;
Meta_Command_Entry_Kind kind;
String_Const_u8 name;
u8 *source_name;
i64 line_number;
union{
struct{
String_Const_u8 doc;
} docstring;
};
};
struct Meta_Command_Entry_Arrays{
Meta_Command_Entry *first_doc_string;
Meta_Command_Entry *last_doc_string;
i32 doc_string_count;
Meta_Command_Entry *first_ui;
Meta_Command_Entry *last_ui;
i32 ui_count;
};
///////////////////////////////
static i32
quick_sort_part(Meta_Command_Entry **entries, i32 first, i32 one_past_last){
i32 pivot = one_past_last - 1;
@ -616,11 +625,50 @@ parse_documented_command(Arena *arena, Meta_Command_Entry_Arrays *arrays, Reader
new_entry->line_number = (i32)string_to_integer(line_number, 10);
new_entry->docstring.doc = doc;
sll_queue_push(arrays->first_doc_string, arrays->last_doc_string, new_entry);
++arrays->doc_string_count;
arrays->doc_string_count += 1;
return(true);
}
static b32
parse_custom_id(Arena *arena, Meta_Command_Entry_Arrays *arrays, Reader *reader){
String_Const_u8 group = {};
String_Const_u8 id = {};
i64 start_pos = 0;
if (!require_key_identifier(reader, "CUSTOM_ID", &start_pos)){
return(false);
}
if (!require_open_parenthese(reader)){
return(false);
}
if (!extract_identifier(reader, &group)){
return(false);
}
if (!require_comma(reader)){
return(false);
}
if (!extract_identifier(reader, &id)){
return(false);
}
if (!require_close_parenthese(reader)){
return(false);
}
Meta_ID_Entry *new_id = push_array(arena, Meta_ID_Entry, 1);
sll_queue_push(arrays->first_id, arrays->last_id, new_id);
new_id->group_name = group;
new_id->id_name = id;
arrays->id_count += 1;
return(true);
}
///////////////////////////////
static void
@ -628,19 +676,16 @@ parse_text(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, u8 *source_nam
Token_List token_list = lex_full_input_cpp(arena, text);
Token_Array array = token_array_from_list(arena, &token_list);
Reader reader_ = make_reader(array, source_name, text);
Reader reader_ = make_reader(arena, array, source_name, text);
Reader *reader = &reader_;
for (;;){
Token token = get_token(reader);
if (token.kind == TokenBaseKind_Identifier){
if (!HasFlag(token.flags, TokenBaseFlag_PreprocessorBody)){
String_Const_u8 lexeme = token_str(text, token);
b32 in_preproc_body = HasFlag(token.flags, TokenBaseFlag_PreprocessorBody);
if (!in_preproc_body &&
string_match(lexeme, string_u8_litexpr("CUSTOM_DOC"))){
if (string_match(lexeme, string_u8_litexpr("CUSTOM_DOC"))){
Temp_Read temp_read = begin_temp_read(reader);
b32 found_start_pos = false;
@ -667,6 +712,14 @@ parse_text(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, u8 *source_nam
}
}
}
else if (string_match(lexeme, string_u8_litexpr("CUSTOM_ID"))){
Temp_Read temp_read = begin_temp_read(reader);
prev_token(reader);
if (!parse_custom_id(arena, entry_arrays, reader)){
end_temp_read(temp_read);
}
}
}
}
if (token.kind == TokenBaseKind_EOF){
@ -762,7 +815,7 @@ main(int argc, char **argv){
Arena arena_ = make_arena_malloc(MB(1), 8);
Arena *arena = &arena_;
char *out_directory = argv[2];
String_Const_u8 out_directory = SCu8(argv[2]);
i32 start_i = 2;
if (recursive){
@ -782,50 +835,43 @@ main(int argc, char **argv){
parse_files_by_pattern(arena, &entry_arrays, pattern_name, recursive);
}
umem out_dir_len = cstring_length(out_directory);
if (out_directory[0] == '"'){
out_directory += 1;
out_dir_len -= 2;
if (out_directory.size > 2 &&
out_directory.str[0] == '"' &&
out_directory.str[out_directory.size - 1] == '"'){
out_directory.str += 1;
out_directory.size -= 2;
}
{
String_Const_u8 str = SCu8(out_directory, out_dir_len);
str = string_skip_chop_whitespace(str);
out_directory = (char*)str.str;
out_dir_len = str.size;
}
out_directory = string_skip_chop_whitespace(out_directory);
umem len = out_dir_len + 1 + sizeof(COMMAND_METADATA_OUT) - 1;
char *out_file_name = (char*)malloc(len + 1);
memcpy(out_file_name, out_directory, out_dir_len);
memcpy(out_file_name + out_dir_len, "/", 1);
memcpy(out_file_name + out_dir_len + 1, COMMAND_METADATA_OUT, sizeof(COMMAND_METADATA_OUT));
String_Const_u8 cmd_out_name = push_u8_stringf(arena, "%.*s/%s",
string_expand(out_directory),
COMMAND_METADATA_OUT);
FILE *cmd_out = fopen((char*)cmd_out_name.str, "wb");
FILE *out = fopen(out_file_name, "wb");
if (out != 0){
if (cmd_out != 0){
i32 entry_count = entry_arrays.doc_string_count;
Meta_Command_Entry **entries = get_sorted_meta_commands(arena, entry_arrays.first_doc_string, entry_count);
fprintf(out, "#if !defined(META_PASS)\n");
fprintf(out, "#define command_id(c) (fcoder_metacmd_ID_##c)\n");
fprintf(out, "#define command_metadata(c) (&fcoder_metacmd_table[command_id(c)])\n");
fprintf(out, "#define command_metadata_by_id(id) (&fcoder_metacmd_table[id])\n");
fprintf(out, "#define command_one_past_last_id %d\n", entry_arrays.doc_string_count);
fprintf(out, "#if defined(CUSTOM_COMMAND_SIG)\n");
fprintf(out, "#define PROC_LINKS(x,y) x\n");
fprintf(out, "#else\n");
fprintf(out, "#define PROC_LINKS(x,y) y\n");
fprintf(out, "#endif\n");
fprintf(cmd_out, "#if !defined(META_PASS)\n");
fprintf(cmd_out, "#define command_id(c) (fcoder_metacmd_ID_##c)\n");
fprintf(cmd_out, "#define command_metadata(c) (&fcoder_metacmd_table[command_id(c)])\n");
fprintf(cmd_out, "#define command_metadata_by_id(id) (&fcoder_metacmd_table[id])\n");
fprintf(cmd_out, "#define command_one_past_last_id %d\n", entry_arrays.doc_string_count);
fprintf(cmd_out, "#if defined(CUSTOM_COMMAND_SIG)\n");
fprintf(cmd_out, "#define PROC_LINKS(x,y) x\n");
fprintf(cmd_out, "#else\n");
fprintf(cmd_out, "#define PROC_LINKS(x,y) y\n");
fprintf(cmd_out, "#endif\n");
fprintf(out, "#if defined(CUSTOM_COMMAND_SIG)\n");
fprintf(cmd_out, "#if defined(CUSTOM_COMMAND_SIG)\n");
for (i32 i = 0; i < entry_count; ++i){
Meta_Command_Entry *entry = entries[i];
fprintf(out, "CUSTOM_COMMAND_SIG(%.*s);\n", str_to_l_c(entry->name));
fprintf(cmd_out, "CUSTOM_COMMAND_SIG(%.*s);\n", string_expand(entry->name));
}
fprintf(out, "#endif\n");
fprintf(cmd_out, "#endif\n");
fprintf(out,
fprintf(cmd_out,
"struct Command_Metadata{\n"
"PROC_LINKS(Custom_Command_Function, void) *proc;\n"
"b32 is_ui;\n"
@ -838,7 +884,7 @@ main(int argc, char **argv){
"i32 line_number;\n"
"};\n");
fprintf(out,
fprintf(cmd_out,
"static Command_Metadata fcoder_metacmd_table[%d] = {\n",
entry_arrays.doc_string_count);
for (i32 i = 0; i < entry_count; ++i){
@ -856,7 +902,7 @@ main(int argc, char **argv){
is_ui = "true";
}
fprintf(out,
fprintf(cmd_out,
"{ PROC_LINKS(%.*s, 0), %s, \"%.*s\", %d, "
"\"%.*s\", %d, \"%s\", %d, %lld },\n",
string_expand(entry->name),
@ -870,23 +916,47 @@ main(int argc, char **argv){
entry->line_number);
end_temp(temp);
}
fprintf(out, "};\n");
fprintf(cmd_out, "};\n");
i32 id = 0;
for (i32 i = 0; i < entry_count; ++i){
Meta_Command_Entry *entry = entries[i];
fprintf(out, "static i32 fcoder_metacmd_ID_%.*s = %d;\n",
string_expand(entry->name), id);
fprintf(cmd_out, "static i32 fcoder_metacmd_ID_%.*s = %d;\n", string_expand(entry->name), id);
++id;
}
fprintf(out, "#endif\n");
fprintf(cmd_out, "#endif\n");
fclose(out);
fclose(cmd_out);
}
else{
fprintf(stdout, "fatal error: could not open output file %s%s\n", out_directory, COMMAND_METADATA_OUT);
fprintf(stdout, "fatal error: could not open output file %.*s\n", string_expand(cmd_out_name));
}
String_Const_u8 id_out_name = push_u8_stringf(arena, "%.*s/%s",
string_expand(out_directory),
ID_METADATA_OUT);
FILE *id_out = fopen((char*)id_out_name.str, "wb");
if (id_out != 0){
fprintf(id_out, "function void\n");
fprintf(id_out, "initialize_managed_id_metadata(Application_Links *app){\n");
for (Meta_ID_Entry *node = entry_arrays.first_id;
node != 0;
node = node->next){
fprintf(id_out, "%.*s = managed_id_declare(app, string_u8_litexpr(\"%.*s\"), string_u8_litexpr(\"%.*s\"));\n",
string_expand(node->id_name),
string_expand(node->group_name),
string_expand(node->id_name));
}
fprintf(id_out, "}\n");
fclose(id_out);
}
else{
fprintf(stdout, "fatal error: could not open output file %.*s\n", string_expand(id_out_name));
}
return(0);

View File

@ -538,10 +538,12 @@ struct Record_Info{
#define CUSTOM_COMMAND_SIG(name) void name(struct Application_Links *app)
#define CUSTOM_UI_COMMAND_SIG(name) void name(struct Application_Links *app)
#define CUSTOM_DOC(str)
#define CUSTOM_ID(group, name) global Managed_ID name;
#else
#define CUSTOM_COMMAND_SIG(name) CUSTOM_COMMAND(name, __FILE__, __LINE__, Normal)
#define CUSTOM_UI_COMMAND_SIG(name) CUSTOM_COMMAND(name, __FILE__, __LINE__, UI)
#define CUSTOM_DOC(str) CUSTOM_DOC(str)
#define CUSTOM_ID(group, name) CUSTOM_ID(group, name)
#endif
// TODO(allen): rename

View File

@ -106,7 +106,7 @@
#define custom_managed_scope_clear_contents_sig() b32 custom_managed_scope_clear_contents(Application_Links* app, Managed_Scope scope)
#define custom_managed_scope_clear_self_all_dependent_scopes_sig() b32 custom_managed_scope_clear_self_all_dependent_scopes(Application_Links* app, Managed_Scope scope)
#define custom_managed_scope_allocator_sig() Base_Allocator* custom_managed_scope_allocator(Application_Links* app, Managed_Scope scope)
#define custom_managed_id_declare_sig() Managed_ID custom_managed_id_declare(Application_Links* app, String_Const_u8 name)
#define custom_managed_id_declare_sig() Managed_ID custom_managed_id_declare(Application_Links* app, String_Const_u8 group, String_Const_u8 name)
#define custom_managed_scope_get_attachment_sig() void* custom_managed_scope_get_attachment(Application_Links* app, Managed_Scope scope, Managed_ID id, umem size)
#define custom_managed_scope_attachment_erase_sig() void* custom_managed_scope_attachment_erase(Application_Links* app, Managed_Scope scope, Managed_ID id)
#define custom_alloc_managed_memory_in_scope_sig() Managed_Object custom_alloc_managed_memory_in_scope(Application_Links* app, Managed_Scope scope, i32 item_size, i32 count)
@ -286,7 +286,7 @@ typedef Managed_Scope custom_get_managed_scope_with_multiple_dependencies_type(A
typedef b32 custom_managed_scope_clear_contents_type(Application_Links* app, Managed_Scope scope);
typedef b32 custom_managed_scope_clear_self_all_dependent_scopes_type(Application_Links* app, Managed_Scope scope);
typedef Base_Allocator* custom_managed_scope_allocator_type(Application_Links* app, Managed_Scope scope);
typedef Managed_ID custom_managed_id_declare_type(Application_Links* app, String_Const_u8 name);
typedef Managed_ID custom_managed_id_declare_type(Application_Links* app, String_Const_u8 group, String_Const_u8 name);
typedef void* custom_managed_scope_get_attachment_type(Application_Links* app, Managed_Scope scope, Managed_ID id, umem size);
typedef void* custom_managed_scope_attachment_erase_type(Application_Links* app, Managed_Scope scope, Managed_ID id);
typedef Managed_Object custom_alloc_managed_memory_in_scope_type(Application_Links* app, Managed_Scope scope, i32 item_size, i32 count);
@ -649,7 +649,7 @@ internal Managed_Scope get_managed_scope_with_multiple_dependencies(Application_
internal b32 managed_scope_clear_contents(Application_Links* app, Managed_Scope scope);
internal b32 managed_scope_clear_self_all_dependent_scopes(Application_Links* app, Managed_Scope scope);
internal Base_Allocator* managed_scope_allocator(Application_Links* app, Managed_Scope scope);
internal Managed_ID managed_id_declare(Application_Links* app, String_Const_u8 name);
internal Managed_ID managed_id_declare(Application_Links* app, String_Const_u8 group, String_Const_u8 name);
internal void* managed_scope_get_attachment(Application_Links* app, Managed_Scope scope, Managed_ID id, umem size);
internal void* managed_scope_attachment_erase(Application_Links* app, Managed_Scope scope, Managed_ID id);
internal Managed_Object alloc_managed_memory_in_scope(Application_Links* app, Managed_Scope scope, i32 item_size, i32 count);

View File

@ -106,7 +106,7 @@ api(custom) function Managed_Scope get_managed_scope_with_multiple_dependencies(
api(custom) function b32 managed_scope_clear_contents(Application_Links* app, Managed_Scope scope);
api(custom) function b32 managed_scope_clear_self_all_dependent_scopes(Application_Links* app, Managed_Scope scope);
api(custom) function Base_Allocator* managed_scope_allocator(Application_Links* app, Managed_Scope scope);
api(custom) function Managed_ID managed_id_declare(Application_Links* app, String_Const_u8 name);
api(custom) function Managed_ID managed_id_declare(Application_Links* app, String_Const_u8 group, String_Const_u8 name);
api(custom) function void* managed_scope_get_attachment(Application_Links* app, Managed_Scope scope, Managed_ID id, umem size);
api(custom) function void* managed_scope_attachment_erase(Application_Links* app, Managed_Scope scope, Managed_ID id);
api(custom) function Managed_Object alloc_managed_memory_in_scope(Application_Links* app, Managed_Scope scope, i32 item_size, i32 count);

View File

@ -0,0 +1,19 @@
function void
initialize_managed_id_metadata(Application_Links *app){
view_rewrite_loc = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("view_rewrite_loc"));
view_next_rewrite_loc = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("view_next_rewrite_loc"));
view_paste_index_loc = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("view_paste_index_loc"));
view_is_passive_loc = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("view_is_passive_loc"));
view_snap_mark_to_cursor = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("view_snap_mark_to_cursor"));
view_ui_data = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("view_ui_data"));
view_highlight_range = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("view_highlight_range"));
view_highlight_buffer = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("view_highlight_buffer"));
view_render_hook = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("view_render_hook"));
view_word_complete_menu = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("view_word_complete_menu"));
buffer_map_id = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("buffer_map_id"));
buffer_eol_setting = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("buffer_eol_setting"));
buffer_lex_task = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("buffer_lex_task"));
buffer_wrap_lines = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("buffer_wrap_lines"));
sticky_jump_marker_handle = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("sticky_jump_marker_handle"));
attachment_tokens = managed_id_declare(app, string_u8_litexpr("attachment"), string_u8_litexpr("attachment_tokens"));
}

View File

@ -17,8 +17,8 @@
#include "4coder_events.h"
#include "4coder_table.h"
#include "4coder_default_colors.h"
#include "4coder_types.h"
#include "4coder_default_colors.h"
#include "4coder_system_types.h"
#define STATIC_LINK_API