commit 7d842414fb66bebd12d71f174c4c90988cb95275
parent c23b9a1cd6cd36e10dad31137f16b77eb710036b
Author: sin <sin@2f30.org>
Date: Thu, 15 May 2014 11:46:49 +0100
Allow to override sym -> object associations
> (define a 5)
ok
> a
5
> (define a 6)
> a
6
Diffstat:
M | sym.c | | | 15 | +++++++++++---- |
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/sym.c b/sym.c
@@ -24,12 +24,19 @@ static struct env *topenv;
struct object *
addsym(char *s, struct object *o)
{
- struct object *otmp;
+ struct env *e;
struct symentry *se;
+ size_t i;
- otmp = lookupsym(s);
- if (otmp)
- return otmp;
+ for (e = topenv; e >= &env[0]; e--) {
+ for (i = 0; i < e->symtab.sz; i++) {
+ se = &e->symtab.se[i];
+ if (strcmp(se->s, s) == 0) {
+ se->o = o;
+ return o;
+ }
+ }
+ }
if (topenv->symtab.sz + 1 > LEN(topenv->symtab.se))
return NULL;
se = &topenv->symtab.se[topenv->symtab.sz];