Skip to content

Commit

Permalink
#245 when lowering generic for statement add locals from the for body
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed Jul 31, 2022
1 parent 15094f3 commit bc1b6b8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ravicomp/src/ast_lower.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ static void lower_for_in_statement(CompilerState *compiler_state, AstNode *node)
{
ForStatement *for_stmt = &node->for_stmt;
AstNode *function = for_stmt->for_scope->function;
Scope *for_body_scope = for_stmt->for_body;

// FIXME - the for variables must be removed from parent scope

Expand Down Expand Up @@ -317,6 +318,11 @@ static void lower_for_in_statement(CompilerState *compiler_state, AstNode *node)
}
END_FOR_EACH_PTR(n2)

LuaSymbol *sym;
FOR_EACH_PTR(for_body_scope->symbol_list, LuaSymbol, sym) {
raviX_add_symbol(compiler_state, &while_scope->symbol_list, sym);
} END_FOR_EACH_PTR(sym)

// Replace the original generic for ast with the new do block
*node = *do_stmt;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/comptests/inputs/74_luajit_andor.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- source https://github.com/LuaJIT/LuaJIT-test-cleanup/blob/master/test/lang/andor.lua

do --- smoke
local x = ((1 or false) and true) or false
assert(x == true)
end

print '74 Ok'
11 changes: 11 additions & 0 deletions tests/comptests/inputs/75_fornum_locals.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local values = {}
for k,v in pairs({ name='Dibyendu', surname='Majumdar' }) do
local key = k
local value = v
values[key] = value
end

assert(values.name == 'Dibyendu')
assert(values.surname == 'Majumdar')

print '75 Ok'

0 comments on commit bc1b6b8

Please sign in to comment.