summaryrefslogtreecommitdiffhomepage
path: root/compiler.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-03-31 10:07:04 +0200
committerJo-Philipp Wich <jo@mein.io>2021-03-31 12:11:02 +0200
commit97bf297aebaca893734edc5d90a225479494c218 (patch)
treee38835ca0566911bd9313eeb98f21aa0aca5e5e2 /compiler.c
parentf0e2a6494b7553a89611bd7062459071119dae3c (diff)
compiler: ensure that alternative if/for/while syntax has own block scope
The `if ...: endif`, `for ...: endfor`, `while ...: endwhile` etc. syntax statements are supposed to have their own lexical scope, like curly brace blocks in normal statements. Without this, local variable declarations within such blocks would incorrectly shift stack offsets for the remainder of the program. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'compiler.c')
-rw-r--r--compiler.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler.c b/compiler.c
index 21e691b..362ca8b 100644
--- a/compiler.c
+++ b/compiler.c
@@ -1867,12 +1867,16 @@ uc_compiler_compile_local(uc_compiler *compiler)
static uc_tokentype_t
uc_compiler_compile_altifblock(uc_compiler *compiler)
{
+ uc_compiler_enter_scope(compiler);
+
while (true) {
switch (compiler->parser->curr.type) {
case TK_ELIF:
case TK_ELSE:
case TK_ENDIF:
case TK_EOF:
+ uc_compiler_leave_scope(compiler);
+
return compiler->parser->curr.type;
default: