From 0db19dcfafe5b2b3cbebaec9098ec50b9d6b1102 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 22 Mar 2025 16:55:57 +0200 Subject: use new hashmap --- src/actualize.c | 6 +++--- src/compiler.c | 3 ++- src/scope.c | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/actualize.c b/src/actualize.c index a846d10..dae9cd9 100644 --- a/src/actualize.c +++ b/src/actualize.c @@ -390,7 +390,7 @@ static int copy_var(bool public, struct scope *to, struct ast *def) static int copy_symbols(bool public, struct scope *to, struct scope *from) { foreach(exported, n, &from->exported_symbols) { - struct ast *def = *n; + struct ast *def = n->data; switch (def->k) { case AST_PROC_DEF: if (copy_proc(public, to, def)) @@ -499,7 +499,7 @@ static int copy_chain(bool public, struct scope *to, struct ast *def) static int copy_types(bool public, struct scope *to, struct scope *from) { foreach(exported, n, &from->exported_types) { - struct ast *def = *n; + struct ast *def = n->data; switch (def->k) { case AST_STRUCT_DEF: if (copy_type(public, to, def, struct_id(def))) @@ -538,7 +538,7 @@ static int copy_types(bool public, struct scope *to, struct scope *from) static int copy_macros(bool public, struct scope *to, struct scope *from) { foreach(exported, n, &from->exported_macros) { - struct ast *def = *n; + struct ast *def = n->data; struct ast *exists = file_scope_find_macro(to, macro_def_id(def)); if (!exists) { diff --git a/src/compiler.c b/src/compiler.c index 6f24ee6..90f5fd0 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -112,6 +112,7 @@ static int process(struct scope *scope, const char *file) #define MAP_KEY char * #define MAP_TYPE struct scope * #define MAP_CMP(a, b) strcmp((a), (b)) +#define MAP_HASH(a) CONTS_MAP_STR_HASH(a) #define MAP_NAME scopes #include @@ -195,7 +196,7 @@ out: } int compile(const char *input) { - scopes = scopes_create(); + scopes = scopes_create(1); int ret = -1; struct scope *root = process_file(input); diff --git a/src/scope.c b/src/scope.c index 4c9097f..c838fe9 100644 --- a/src/scope.c +++ b/src/scope.c @@ -28,14 +28,14 @@ struct scope *create_scope() return NULL; } - scope->expanded = expanded_create(); - scope->symbols = visible_create(); - scope->macros = visible_create(); - scope->types = visible_create(); + scope->expanded = expanded_create(4); + scope->symbols = visible_create(4); + scope->macros = visible_create(4); + scope->types = visible_create(4); - scope->exported_symbols = exported_create(); - scope->exported_macros = exported_create(); - scope->exported_types = exported_create(); + scope->exported_symbols = exported_create(4); + scope->exported_macros = exported_create(4); + scope->exported_types = exported_create(4); scope->number = counter++; return scope; @@ -495,7 +495,7 @@ bool is_exported_macro(struct scope *scope, struct ast *def) int scope_add_exported_symbol(struct scope *scope, struct ast *def) { - struct ast **inserted = exported_insert(&scope->exported_symbols, def); + struct ast **inserted = exported_insert(&scope->exported_symbols, def, def); if (!inserted) { internal_error("failed inserting exported symbol"); return -1; @@ -507,7 +507,7 @@ int scope_add_exported_symbol(struct scope *scope, struct ast *def) int scope_add_exported_type(struct scope *scope, struct ast *def) { - struct ast **inserted = exported_insert(&scope->exported_types, def); + struct ast **inserted = exported_insert(&scope->exported_types, def, def); if (!inserted) { internal_error("failed inserting exported type"); return -1; @@ -533,7 +533,7 @@ int scope_add_exported_chain(struct scope *scope, struct ast *def) assert(exported_find(&scope->exported_types, def) == NULL); remove_exported_chain(scope, def->chain); - struct ast **inserted = exported_insert(&scope->exported_types, def); + struct ast **inserted = exported_insert(&scope->exported_types, def, def); if (!inserted) { internal_error("failed inserting exported chain"); return -1; @@ -545,7 +545,7 @@ int scope_add_exported_chain(struct scope *scope, struct ast *def) int scope_add_exported_macro(struct scope *scope, struct ast *def) { - struct ast **inserted = exported_insert(&scope->exported_macros, def); + struct ast **inserted = exported_insert(&scope->exported_macros, def, def); if (!inserted) { internal_error("failed inserting exported macro"); return -1; -- cgit v1.3