feat: replace Scope stack with Local array to fix variable shadowing in nested blocks

Replace the linked-list Scope structure with a flat Local array indexed by depth, enabling proper shadowing semantics where inner declarations correctly hide outer ones. Remove the PUSH_SCOPE/POP_SCOPE macros and the SymbolTable-based locals tracking, replacing them with a MAX_LOCALS (255) fixed-size array that stores variable name, length, and depth. Add four new test cases covering local/parameter collision, nested block scoping, global shadowing, and local shadowing to validate the new behavior.
This commit is contained in:
Bob Nystrom
2013-12-01 02:28:01 +00:00
parent 2f37b99eef
commit 4240e46e05
7 changed files with 186 additions and 113 deletions
@@ -0,0 +1,3 @@
fn(a) {
var a = "oops" // expect error
}
+6
View File
@@ -0,0 +1,6 @@
{
var a = "outer"
{
io.write(a) // expect: outer
}
}
+6
View File
@@ -0,0 +1,6 @@
var a = "global"
{
var a = "shadow"
io.write(a) // expect: shadow
}
io.write(a) // expect: global
+8
View File
@@ -0,0 +1,8 @@
{
var a = "local"
{
var a = "shadow"
io.write(a) // expect: shadow
}
io.write(a) // expect: local
}