From fed011fc52354340cfb353ee74c57ba0c81169fb Mon Sep 17 00:00:00 2001 From: Miguel Lechon Date: Tue, 16 Mar 2021 11:11:13 +0100 Subject: [PATCH] Switch to map_proposal. --- .../static_site_generator/static_site_generator.c | 6 +++--- source/md.h | 5 ++++- source/md_impl.c | 7 +++++-- tests/grammar.c | 12 ++++++------ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/samples/static_site_generator/static_site_generator.c b/samples/static_site_generator/static_site_generator.c index be4dc3f..e7404b9 100644 --- a/samples/static_site_generator/static_site_generator.c +++ b/samples/static_site_generator/static_site_generator.c @@ -516,11 +516,11 @@ GeneratePageContent(MD_NodeTable *index_table, SiteInfo *site_info, PageInfo *pa for(MD_NodeTableSlot *slot = MD_NodeTable_Lookup(index_table, index_string->string); slot; slot = slot->next) { - if(slot->node) + if(slot->value) { - PageInfo info = ParsePageInfo(slot->node); + PageInfo info = ParsePageInfo((MD_Node *)slot->value); - MD_String8 filename = slot->node->filename; + MD_String8 filename = ((MD_Node *)slot->value)->filename; MD_String8 filename_no_ext = MD_ChopExtension(MD_SkipFolder(filename)); MD_String8 link = MD_PushStringF("%.*s.html", MD_StringExpand(filename_no_ext)); MD_String8 name = info.title->string; diff --git a/source/md.h b/source/md.h index c177bd5..13e0ab7 100644 --- a/source/md.h +++ b/source/md.h @@ -385,7 +385,7 @@ typedef enum MD_MessageKind MD_MessageKind; //~ String-To-Node table - +#if 0 typedef enum MD_NodeTableCollisionRule { MD_NodeTableCollisionRule_Chain, @@ -407,6 +407,9 @@ struct MD_NodeTable MD_u64 table_size; MD_NodeTableSlot **table; }; +#else +#include "map_proposal.h" +#endif //~ Token kinds. diff --git a/source/md_impl.c b/source/md_impl.c index a12a0aa..6d6675c 100644 --- a/source/md_impl.c +++ b/source/md_impl.c @@ -947,7 +947,7 @@ MD_S32FromS8(MD_String8 in) return(result); } - +#if 0 MD_PRIVATE_FUNCTION_IMPL void _MD_NodeTable_Initialize(MD_NodeTable *table) { @@ -1027,6 +1027,9 @@ MD_NodeTable_Insert(MD_NodeTable *table, MD_NodeTableCollisionRule collision_rul return !!slot; } +#else +#include "map_proposal.c" +#endif MD_FUNCTION_IMPL MD_b32 MD_TokenKindIsWhitespace(MD_TokenKind kind) @@ -1990,7 +1993,7 @@ MD_ParseWholeString(MD_String8 filename, MD_String8 contents) MD_NodeTable_Insert(&ctx.namespace_table, MD_NodeTableCollisionRule_Overwrite, token.string, ns); existing_namespace_slot = MD_NodeTable_Lookup(&ctx.namespace_table, token.string); } - ctx.selected_namespace = existing_namespace_slot->node; + ctx.selected_namespace = (MD_Node *)existing_namespace_slot->value; } else { diff --git a/tests/grammar.c b/tests/grammar.c index 5fe05a6..a75c2ec 100644 --- a/tests/grammar.c +++ b/tests/grammar.c @@ -251,7 +251,7 @@ static void ExpandRule(MD_Node *rule, MD_String8List *out_strings, MD_Node *cur_ } else // NOTE(mal): Non-terminal production { - MD_Node * production = MD_NodeTable_Lookup(globals.production_table, rule_element->string)->node; + MD_Node * production = MD_NodeTable_Lookup(globals.production_table, rule_element->string)->value; MD_Assert(production); ExpandProduction(production, out_strings, cur_node, op_flags, max_depth, depth+1); } @@ -314,7 +314,7 @@ static MD_Node * FindNonTerminalProduction(MD_Node *node, MD_NodeTable *visited) MD_NodeTableSlot *slot = MD_NodeTable_Lookup(globals.production_table, node->string); if(slot) { - MD_Node *production = slot->node; + MD_Node *production = slot->value; result = FindNonTerminalProduction(production, visited); } else @@ -429,7 +429,7 @@ static void ComputeElementDepth(MD_Node *re) } else { - MD_Node * production = MD_NodeTable_Lookup(globals.production_table, re->string)->node; + MD_Node * production = MD_NodeTable_Lookup(globals.production_table, re->string)->value; result = GET_DEPTH(production)+1; } } @@ -592,7 +592,7 @@ int main(int argument_count, char **arguments) fprintf(stderr, "Error: Grammar file does not specify \"file\" production\n"); goto error; } - file_production = file_production_slot->node; + file_production = file_production_slot->value; } // NOTE(mal): Check that all branches lead to terminal nodes @@ -641,7 +641,7 @@ int main(int argument_count, char **arguments) MD_Assert(MD_NodeIsNil(rule_element->first_child)); if(!(rule_element->flags & MD_NodeFlag_CharLiteral)) { - MD_Node * production = MD_NodeTable_Lookup(globals.production_table, rule_element->string)->node; + MD_Node * production = MD_NodeTable_Lookup(globals.production_table, rule_element->string)->value; depth = GET_DEPTH(production); } depth += 1; @@ -694,7 +694,7 @@ int main(int argument_count, char **arguments) RandomSeries random_series = rand_seed(0, 0); // NOTE(mal): Reproduceable globals.random_series = &random_series; - MD_Node* file_production_node = MD_NodeTable_Lookup(globals.production_table, MD_S8Lit("file"))->node; + MD_Node* file_production_node = MD_NodeTable_Lookup(globals.production_table, MD_S8Lit("file"))->value; // NOTE(mal): Generate test_count unique tests, sorted by complexity MD_u32 test_count = 1000;