fix: correct local variable storage and remove premature local slot allocation in vm

The compiler's storeVariable function was incorrectly emitting CODE_STORE_LOCAL for all variables, including locals that already have their value in the correct stack slot. This change renames storeVariable to defineVariable and adds logic to only emit CODE_STORE_GLOBAL for globals, while for locals it emits CODE_DUP to preserve the value through the subsequent POP. Additionally, the vm's callFunction no longer pre-allocates empty slots for locals, as they are now placed on the stack during compilation. New test files verify duplicate local/parameter detection and correct local variable ordering in block scopes.
This commit is contained in:
Bob Nystrom
2013-11-09 19:38:01 +00:00
parent d43a62e08c
commit 04dda643d0
9 changed files with 64 additions and 16 deletions
+1
View File
@@ -0,0 +1 @@
var true = "value" // expect error