declare the variables introduced by for loop into scope #44

This commit is contained in:
leaf corcoran 2012-09-18 16:04:22 -07:00
parent 43c1e0a4fb
commit 98ebb97b16
3 changed files with 8 additions and 2 deletions

View File

@ -157,6 +157,9 @@ line_compile = {
}), " do") }), " do")
do do
local _with_0 = self:block(loop) local _with_0 = self:block(loop)
_with_0:declare({
name
})
_with_0:stms(block) _with_0:stms(block)
return _with_0 return _with_0
end end
@ -195,6 +198,7 @@ line_compile = {
end end
do do
local _with_0 = self:block(loop) local _with_0 = self:block(loop)
_with_0:declare(names)
_with_0:stms(block) _with_0:stms(block)
return _with_0 return _with_0
end end

View File

@ -91,6 +91,7 @@ line_compile =
_, name, bounds, block = unpack node _, name, bounds, block = unpack node
loop = @line "for ", @name(name), " = ", @value({"explist", unpack bounds}), " do" loop = @line "for ", @name(name), " = ", @value({"explist", unpack bounds}), " do"
with @block loop with @block loop
\declare {name}
\stms block \stms block
-- for x in y ... -- for x in y ...
@ -106,6 +107,7 @@ line_compile =
\append " do" \append " do"
with @block loop with @block loop
\declare names
\stms block \stms block
export: (node) => export: (node) =>

View File

@ -197,8 +197,8 @@ local hello = (function()
for _index_0 = 1, #_list_1 do for _index_0 = 1, #_list_1 do
x = _list_1[_index_0] x = _list_1[_index_0]
local _list_2 = items local _list_2 = items
for _index_0 = 1, #_list_2 do for _index_1 = 1, #_list_2 do
local y = _list_2[_index_0] local y = _list_2[_index_1]
_len_0 = _len_0 + 1 _len_0 = _len_0 + 1
_accum_0[_len_0] = x + y _accum_0[_len_0] = x + y
end end