harec

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

commit 416e6b362d6d0c747fada4713159c0c6a0c8cf89
parent a225cfca23cd9ae3c7a6f17c22d69622ee1d490e
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 19 Feb 2021 13:59:08 -0500

Implement variable shadowing

Diffstat:
Minclude/scope.h | 4++--
Msrc/scope.c | 6++++--
2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/scope.h b/include/scope.h @@ -20,13 +20,13 @@ struct scope_object { struct identifier name, ident; const struct type *type; struct expression *value; // For O_CONST - struct scope_object *next; + struct scope_object *next, *prev; }; struct scope { enum expr_type type; const char *label; - struct scope_object *objects; + struct scope_object *objects, *last; struct scope_object **next; // List order matters for functions struct scope *parent; }; diff --git a/src/scope.c b/src/scope.c @@ -78,19 +78,21 @@ scope_insert(struct scope *scope, enum object_type otype, } *scope->next = o; scope->next = &o->next; + o->prev = scope->last; + scope->last = o; return o; } const struct scope_object * scope_lookup(struct scope *scope, const struct identifier *ident) { - struct scope_object *o = scope->objects; + struct scope_object *o = scope->last; while (o) { if (identifier_eq(&o->ident, ident) || identifier_eq(&o->name, ident)) { return o; } - o = o->next; + o = o->prev; } if (scope->parent) { return scope_lookup(scope->parent, ident);