harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit c00565ef073690cf14fe1aa89bd8565abe521749
parent 2ee15aa5ce2e1e5bde880dd53e8bf5631f96f014
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date:   Sun, 20 Feb 2022 01:58:58 +0100

don't try to match object.ident in scope_lookup

This prevents having two ways to refer to the same module-local object
and makes our name resolution conceptually much more straightforward.

Signed-off-by: Bor Grošelj Simić <bor.groseljsimic@telemach.net>

Diffstat:
Minclude/types.h | 1+
Mrt/ensure.ha | 4++--
Msrc/check.c | 5++++-
Msrc/scope.c | 3+--
Msrc/type_store.c | 3++-
5 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/include/types.h b/include/types.h @@ -49,6 +49,7 @@ struct type; struct type_alias { struct identifier ident; + struct identifier name; const struct type *type; bool exported; // Used to make sure unexported aliases aren't emitted }; diff --git a/rt/ensure.ha b/rt/ensure.ha @@ -84,10 +84,10 @@ fn reverse(b: []u8) void = { fn println(msgs: str...) void = { for (let i = 0z; i < len(msgs); i += 1) { let msg = msgs[i]; - rt::write(1, *(&msg: **void): *const char, len(msg)): void; + write(1, *(&msg: **void): *const char, len(msg)): void; if (i + 1 < len(msgs)) { const sp = " "; - rt::write(1, *(&sp: **void): *const char, 1): void; + write(1, *(&sp: **void): *const char, 1): void; }; }; const linefeed = "\n"; diff --git a/src/check.c b/src/check.c @@ -3096,6 +3096,7 @@ check_type(struct context *ctx, .storage = STORAGE_ALIAS, .alias = { .ident = decl->ident, + .name = adecl->ident, .type = type, .exported = exported, }, @@ -3455,13 +3456,15 @@ static const struct scope_object * scan_type(struct context *ctx, struct ast_type_decl *decl, bool exported, struct dimensions dim) { - struct identifier ident = {0}; + struct identifier ident = {0}, name = {0}; mkident(ctx, &ident, &decl->ident); + identifier_dup(&name, &decl->ident); struct type _alias = { .storage = STORAGE_ALIAS, .alias = { .ident = ident, + .name = name, .type = NULL, .exported = exported, }, diff --git a/src/scope.c b/src/scope.c @@ -132,8 +132,7 @@ scope_lookup(struct scope *scope, const struct identifier *ident) uint32_t hash = name_hash(FNV1A_INIT, ident); struct scope_object *bucket = scope->buckets[hash % SCOPE_BUCKETS]; while (bucket) { - if (identifier_eq(&bucket->name, ident) - || identifier_eq(&bucket->ident, ident)) { + if (identifier_eq(&bucket->name, ident)) { return bucket; } bucket = bucket->mnext; diff --git a/src/type_store.c b/src/type_store.c @@ -665,6 +665,7 @@ type_init_from_atype(struct type_store *store, break; } identifier_dup(&type->alias.ident, &obj->ident); + identifier_dup(&type->alias.name, &obj->name); type->alias.type = obj->type->alias.type; type->size = obj->type->size; type->align = obj->type->align; @@ -903,7 +904,7 @@ type_store_lookup_type(struct type_store *store, const struct type *type) // alias was defined with struct type psuedotype = *type; const struct scope_object *obj = scope_lookup( - store->check_context->scope, &type->alias.ident); + store->check_context->scope, &type->alias.name); psuedotype.flags |= obj->type->flags; return type_store_lookup_alias(store, &psuedotype, true); }