diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-24 21:24:19 +0000 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-24 21:24:19 +0000 |
commit | a4cc3e44e0fcf15159c68f7af45e8decd0c30ba4 (patch) | |
tree | 190517effb2fb585ad9e3a588ac2aaf646dbff46 | |
parent | 468e0f6313fb620bd2f7ea469178fe02412ddc31 (diff) |
Make sure variables are as local as they need to be
-rw-r--r-- | eval.c | 3 | ||||
-rw-r--r-- | symbol.c | 4 |
2 files changed, 7 insertions, 0 deletions
@@ -229,6 +229,9 @@ assign(Datum left, Datum right) if(left.symbol->setfn != nil) left.symbol->setfn(right); else{ + /* re-assign the symbol to one that is sure to be local. This enables shadowing */ + left.symbol = getsym(left.symbol->name, 1); + if(left.symbol->undefined == 0 && left.symbol->value.tag == ArrayTag) freearray(left.symbol->value.array); left.symbol->value = right; @@ -38,6 +38,10 @@ getsym(Rune *name, int fresh) done = 1; }while(!done && !fresh); + /* make sure to allocate in the most local scope if the symbol is not found */ + if(currentdfn) + tab = currentdfn->symtab; + tab->nsyms++; tab->syms = realloc(tab->syms, sizeof(Symbol *) * tab->nsyms); tab->syms[tab->nsyms-1] = emalloc(sizeof(Symbol)); |